SDL2 Linux problems

Hello, I’ve been following Lazy Foo’s SDL2 tutorials and making games in Windows for a while now. The SDL stuff has always ran flawlessly on Windows. However, I recently got a Chromebook and installed Ubuntu xfce on it so I could test my games on a different operating system and with low computer specs and so I could use Valgrind to find memory leaks.

So I downloaded Lazy Foo’s Scrolling program, changed all instances of NULL to nullptr, and compiled it on my Linux build. However, when I ran the program, there were some problems. I could see each individual frame and the dot was jumping quite a distance each frame. Worse, a white line was continuously flashing at the top of the window.

I then modified the program to remove vsync and cap the frame rate manually to 60 fps like in Lazy Foo’s Capping Frame Rate tutorial. When I ran that program, the white flashing was gone and the dot moved more smoothly, but the program ran slower.

Worse, Valgrind is detecting memory leaks in both programs. Does anyone know where they might be?

Does anyone know what could be wrong with my Linux programs? How do I get them to behave like their Windows counterparts?

If anyone wants me to post the programs or videos of the programs in action, let me know and I’ll do it.

Without seeing at least an outline of your code I don’t know, but I encountered similar problems when first porting SDL programs from Windows to Linux. They were all my own fault, caused by not following the ‘rules’ correctly.

If you are currently using the Direct3D render backend (which is the default in Windows) I would suggest that you switch to using OpenGL, which is likely what is being used in Linux. If that still works in Windows it’s a good sign that your code is OK; add this before your SDL_CreateWindow():


I tried that and the same thing is happening. Nothing changed.

So, just to be clear, with that hint added it still runs OK in Windows? Adding the hint is unlikely to affect how it runs in Linux (which is using OpenGL already).

Yes. It still runs O.K. in Windows.

1 Like