I have a problem presenting to a plain SDL2 Window on Linux.
I’ve been developing a Vulkan game engine using SDL2 for the window creation (SDL_WINDOW_VULKAN flag), input, audio etc.
This has worked flawlessly for two years, and continues to work very well.
I decided to try and make a launcher window, so the user can pre-select the game screen resolution, windowed / full screen mode, before starting the game.
This would be integrated into the engine, so the idea is to open a basic SDL2 window and draw UI elements into it with custom UI code.
(I know there are window UI options like wxWidgets, and GTK, but I want to reduce dependencies as much as possible.)
Once the selections have been made, the window will be close, then a SDL2 Vulkan window will be created, and the game starts.
But, I cannot get a simple VSynced SDL2 window to work reliably.
First I tried creating a VSynced SDL2 window and rendering an image to it, but when the application was started it would randomly display the image.
Confused by this, I simplified it and just cleared the screen with a clear colour - same problem, either it cleared the screen or it didn’t, randomly.
Simplifying further, I created a (isolated from my engine) console test program (SDL_clear_window.cpp), that would Init SDL, create a VSynced window, create an accelerated renderer, clear it with white, then SDL_RenderPresent() 120 frames in a loop (this should take 2 seconds on my laptop’s 60Hz VSynced display), then close everything down.
A full stop is sent to the console via printf to indicate each frame iteration.
When this test application was started, again, it would randomly finish early (instantly sometimes), or present the screen as rapid white flashes, like as if it were presenting white, then black, then white, black, white…
At my wits end, I created a run.sh script to run the application ten times whilst timing each iteration time, with a 3 second delay between restarts (to give the system time to settle down). I got these timings:
Loop index 1: 1.605
Loop index 2: 0.215
Loop index 3: 1.188
Loop index 4: 0.200
Loop index 5: 0.202
Loop index 6: 0.217
Loop index 7: 0.208
Loop index 8: 2.070
Loop index 9: 0.186
Loop index 10: 0.214
As you can see, loop index 8 ran for two seconds as expected, but the the others are all over the place, some quitting instantly.
My SDL_clear_window.cpp C++ file is checking every SDL2 call for errors, there are none.
Thinking that I’m going insane, I tried these github repos: https://github.com/AlmasB/SDL2-Demo and https://github.com/spacejack/sdl2-examples (helloSDLcpp).
Both of those did not show any window contents.
All the above was compiled and executed on my DELL E6230 development laptop running Kubuntu studio 20.04.1 (X11 session) with a low-latency kernel, and SDL2.0.10 as that’s the current repo version.
I also tried my SDL_clear_window.cpp test program on a DELL E5470 laptop running a live USB Ubuntu 20.04.1 (X11 session) - same problem. Again SDL2.0.10.
Finally I created a VS2019 solution using my SDL_clear_window.cpp test program, and lo and behold, I had a window appear, with a white background, no flickering, which closed two seconds later. This project used SDL2.0.12.
All cases use the intel integrated GPU, including the Win 10 project.
Which brings me to my question…
Does anyone have any ideas, something else I can try to figure out why this simple SDL2 window code doesn’t run on my Linux machines?
Using SDL_RENDERER_SOFTWARE resulted in the error ‘Couldn’t find matching render driver’.
Since the Vulkan flagged SDL2 window works perfectly, I’m seriously considering creating a Vulkan accelerated launch window, closing that after the options are selected, then creating a new Vulkan window for the main game (with the selected options), only because it works so reliably.
Or I could look into wxWidgets / GTK and see how much work that is to integrate it into my engine, (I’d rather not go down this route as previously mentioned).
I have the SDL_clear_window.cpp based Linux project with build info as a zip file, available below from my GDrive as I don’t know where else to put it, sorry.
A video of the effect is available here:
Any help would be appreciated.
Development Laptop Kubuntu studio 20.04.1 (X11 session)
*OS: Ubuntu 20.04.1 LTS x86_64 *
*Host: Latitude E6230 01 *
*Kernel: 5.4.0-45-lowlatency *
*Shell: bash 5.0.17 *
*Resolution: 1366x768 *
*DE: Plasma *
*WM: KWin *
*Theme: Breeze [Plasma], Breeze [GTK2/3] *
*Icons: breeze [Plasma], breeze [GTK2/3] *
*Terminal: konsole *
*CPU: Intel i5-3340M (4) @ 3.400GHz *
*GPU: Intel 3rd Gen Core processor Graphics Controller *
*Memory: 1457MiB / 7865MiB *
VGA compatible controller: Intel Corporation 3rd Gen Core processor Graphics Controller (rev 09)
Alternative Test Laptop running a live USB Ubuntu 20.04.1 (X11 session) - same problem
*OS: Ubuntu 20.04.1 LTS x86_64 *
*Host: Latitude E5470 *
*Kernel: 5.4.0-42-generic *
*Resolution: 1920x1080 *
*DE: GNOME *
*WM: Mutter *
*WM Theme: Adwaita *
*Theme: Yaru [GTK2/3] *
*Icons: Yaru [GTK2/3] *
*Terminal: gnome-terminal *
*CPU: Intel i5-6300U (4) @ 3.000GHz *
*GPU: Intel Skylake GT2 [HD Graphics 520] *
*Memory: 990MiB / 7629MiB *
VGA compatible controller: Intel Corporation Skylake GT2 [HD Graphics 520] (rev 07)