SDL3: Assertion failure at SDL_UnlockMutex_REAL while using the software renderer
I encountered the following error when attempting to use the software renderer to render a window with a solid color and resizing the window. Running the snake example and resizing the window also causes the same error. Using the GL or vulkan driver seems to work fine though.
I'm using Arch Linux, and the main callback method for driving the app.
What's the call stack?
The snake game doesn't trigger it here, but I had to change the window creation to allow resizing. X11+software renderer.
Here's the call stack for the snake example:
Starting program: /home/chip/dev/SDL/build/examples/game-snake
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff12006c0 (LWP 382736)]
[New Thread 0x7ffff08006c0 (LWP 382737)]
[New Thread 0x7fffefe006c0 (LWP 382738)]
[New Thread 0x7fffef4006c0 (LWP 382741)]
[New Thread 0x7fffee8006c0 (LWP 382743)]
[New Thread 0x7fffeca006c0 (LWP 382746)]
ERROR: Failed to acquire swapchain texture:
ERROR: Failed to acquire swapchain texture:
WARNING:
Assertion failure at SDL_UnlockMutex_REAL (/home/chip/dev/SDL/src/thread/pthread/SDL_sysmutex.c:150), triggered 1 time:
'rc == 0'
[Detaching after fork from child process 383701]
Thread 1 "game-snake" received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff7cf6deb in SDL_UnlockMutex_REAL () from /home/chip/dev/SDL/build/libSDL3.so.0
(gdb) where
#0 0x00007ffff7cf6deb in SDL_UnlockMutex_REAL () from /home/chip/dev/SDL/build/libSDL3.so.0
#1 0x00007ffff7d18ae8 in VULKAN_Submit () from /home/chip/dev/SDL/build/libSDL3.so.0
#2 0x00007ffff7d18228 in VULKAN_SubmitAndAcquireFence () from /home/chip/dev/SDL/build/libSDL3.so.0
#3 0x00007ffff7a96a2d in SDL_SubmitGPUCommandBufferAndAcquireFence_REAL ()
from /home/chip/dev/SDL/build/libSDL3.so.0
#4 0x00007ffff7ac5971 in GPU_RenderPresent () from /home/chip/dev/SDL/build/libSDL3.so.0
#5 0x00007ffff7ac0a87 in SDL_RenderPresent_REAL () from /home/chip/dev/SDL/build/libSDL3.so.0
#6 0x00007ffff7a70ddf in SDL_RenderPresent () from /home/chip/dev/SDL/build/libSDL3.so.0
#7 0x0000555555555d2e in SDL_AppIterate ()
#8 0x00007ffff7ab0182 in SDL_IterateMainCallbacks () from /home/chip/dev/SDL/build/libSDL3.so.0
#9 0x00007ffff7d1d550 in SDL_EnterAppMainCallbacks_REAL () from /home/chip/dev/SDL/build/libSDL3.so.0
#10 0x00007ffff7a6c19e in SDL_EnterAppMainCallbacks () from /home/chip/dev/SDL/build/libSDL3.so.0
#11 0x0000555555555285 in SDL_main ()
#12 0x00007ffff7ab0248 in SDL_RunApp_REAL () from /home/chip/dev/SDL/build/libSDL3.so.0
#13 0x00007ffff7a651f6 in SDL_RunApp_DEFAULT () from /home/chip/dev/SDL/build/libSDL3.so.0
#14 0x00007ffff7a71213 in SDL_RunApp () from /home/chip/dev/SDL/build/libSDL3.so.0
#15 0x00005555555552b0 in main ()
A similar call stack from my test application:
Using host libthread_db library "/usr/lib/libthread_db.so.1".
info: Available render drivers (5):
info: - gpu
info: - opengl
info: - opengles2
info: - vulkan
info: - software
[New Thread 0x7ffff12006c0 (LWP 395957)]
[New Thread 0x7ffff08006c0 (LWP 395958)]
[New Thread 0x7fffefe006c0 (LWP 395959)]
[New Thread 0x7fffef2006c0 (LWP 395961)]
[New Thread 0x7fffee8006c0 (LWP 395963)]
[New Thread 0x7fffe16006c0 (LWP 396061)]
[New Thread 0x7fffe0c006c0 (LWP 396062)]
[New Thread 0x7fffd7e006c0 (LWP 396067)]
[New Thread 0x7fffd74006c0 (LWP 396069)]
ERROR: Failed to acquire swapchain texture:
WARNING:
Assertion failure at SDL_UnlockMutex_REAL (/home/chip/dev/SDL/src/thread/pthread/SDL_sysmutex.c:150), triggered 1 time:
'rc == 0'
[Detaching after fork from child process 396250]
Thread 1 "zpixel" received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff7cf6deb in SDL_UnlockMutex_REAL () from /home/chip/dev/zpixel/lib/libSDL3.so.0
(gdb) where
#0 0x00007ffff7cf6deb in SDL_UnlockMutex_REAL () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#1 0x00007ffff7d18ae8 in VULKAN_Submit () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#2 0x00007ffff7d18228 in VULKAN_SubmitAndAcquireFence () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#3 0x00007ffff7a96a2d in SDL_SubmitGPUCommandBufferAndAcquireFence_REAL ()
from /home/chip/dev/zpixel/lib/libSDL3.so.0
#4 0x00007ffff7ac5971 in GPU_RenderPresent () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#5 0x00007ffff7ac0a87 in SDL_RenderPresent_REAL () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#6 0x00007ffff7bd4577 in SDL_UpdateWindowTexture () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#7 0x00007ffff7bdbdb3 in SDL_UpdateWindowSurfaceRects_REAL () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#8 0x00007ffff7bdbc9a in SDL_UpdateWindowSurface_REAL () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#9 0x00007ffff7b13fc7 in SW_RenderPresent () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#10 0x00007ffff7ac0a87 in SDL_RenderPresent_REAL () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#11 0x00007ffff7a70ddf in SDL_RenderPresent () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#12 0x00000000010e5963 in main.SDL_AppIterate (appstate=0x7ffff7fbe000) at main.zig:71
#13 0x00007ffff7ab0182 in SDL_IterateMainCallbacks () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#14 0x00007ffff7d1d550 in SDL_EnterAppMainCallbacks_REAL () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#15 0x00007ffff7a6c19e in SDL_EnterAppMainCallbacks () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#16 0x000000000103824b in c.SDL_main (arg_argc=1, arg_argv=0x7fffffffdf48)
at /home/chip/dev/zpixel/.zig-cache/o/9e74474b4aff924b6bec2f711e069d43/c.zig:4238
#17 0x00007ffff7ab0248 in SDL_RunApp_REAL () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#18 0x00007ffff7a651f6 in SDL_RunApp_DEFAULT () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#19 0x00007ffff7a71213 in SDL_RunApp () from /home/chip/dev/zpixel/lib/libSDL3.so.0
#20 0x00000000010381da in c.main (arg_argc=1, arg_argv=0x7fffffffdf48)
at /home/chip/dev/zpixel/.zig-cache/o/9e74474b4aff924b6bec2f711e069d43/c.zig:4248
(Is it possible to get the line numbers? I ran the binaries in gdb and pressed the "Break" button in the dialog, but maybe there's a better way?)
The ERROR: Failed to acquire swapchain texture: doesn't always show up. The dialog doesn't always show up either - but it's clear the program stops doing a render swap. Also, some resizing of the window seems to be fine (i.e. the error doesn't always happen as soon as you do a tiny resize). Making the window resizable does not make a difference for me.
Not sure it's normal that vulkan is called when using the software renderer. I'm creating the renderer like this:
SDL_CreateRenderer(win, "software")
This does not cause the issue:
SDL_CreateRenderer(win, "vulkan")
The GPU renderer is no longer default, we can close this.