Closed def- closed 2 years ago
I haven't checked this in detail yet, but in case someone with more experience is able to figure this out quicker than I can, reverting the mentioned PR (https://github.com/libsdl-org/SDL/pull/4242) resolves the issue completely on my end.
After going through the mentioned PR for a bit, the backing issue (https://github.com/libsdl-org/SDL/issues/3680) doesn't look like a case that would affect our project. It would be quite helpful for now defining a flag/hint to switch between dispatch_sync
and dispatch_async
for context update, to avoid this issue at our side.
Is this issue resolved now that the hint patch is merged? (disregarding for a moment my after-the-fact idea in #5708 of changing the hint's behavior a little.)
Testing on my end with an M1 machine on an SDL game with multi-threaded model, I can confirm this is fully resolved now!
Great, thanks!
By very aggressively moving the window and resizing it between two screens, using Rectangle, I am still getting a crash. Not sure if this is a new issue since it happens in SDL_PollEvent now:
This is https://github.com/ddnet/ddnet with this diff to remove our workaround for this issue:
diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp
index 060774731..05912db57 100644
--- a/src/engine/client/graphics_threaded.cpp
+++ b/src/engine/client/graphics_threaded.cpp
@@ -2755,11 +2755,6 @@ void CGraphics_Threaded::Swap()
// kick the command buffer
KickCommandBuffer();
- // TODO: Remove when https://github.com/libsdl-org/SDL/issues/5203 is fixed
-#ifdef CONF_PLATFORM_MACOS
- if(str_find(GetVersionString(), "Metal"))
- WaitForIdle();
-#endif
}
bool CGraphics_Threaded::SetVSync(bool State)
In that crash report, thread 0 (the main thread) is doing the OpenGL context update that was sent through a dispatch queue, while thread 9 (the rendering thread?) is calling into the GL to draw, and this is causing a crash inside the GL.
Which leads me to ask: are you sure you used the right build of SDL? The latest in revision control, that changed the hint to default to synchronous updates? I don't see any threads that appear to be blocked, waiting on that update in the main thread to finish, which would cause this sort of crash.
Thanks for checking that, I was indeed using wrong version. Didn't know this was changed recently and not yet released. Current master (9f30d4981e8a48720f49887fdded30da8e0d452b) works fine for me, couldn't get any crash even after aggressively moving and resizing window for minutes.
This is on macOS with an M1 ARM64 CPU. Crash originally reported in https://github.com/ddnet/ddnet/issues/4435
To reproduce run DDNet client, which uses SDL2. Resize or move the window to a different screen to trigger a crash sporadically.
Crash log (click to expand)
``` ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Process: DDNet [13312] Path: /Users/USER/*/DDNet Identifier: DDNet Version: ??? Code Type: ARM-64 (Native) Parent Process: zsh [12485] Responsible: iTerm2 [748] User ID: 501 Date/Time: 2022-01-08 11:51:43.5711 +0100 OS Version: macOS 12.1 (21C52) Report Version: 12 Anonymous UUID: 3AB7E5C0-6273-0D0C-4A67-105D60AF53FE Time Awake Since Boot: 8100 seconds System Integrity Protection: enabled Crashed Thread: 7 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Application Specific Information: dyld4 config: DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib -[AGXG13XFamilyCommandBuffer renderCommandEncoderWithDescriptor:]:380: failed assertion `A command encoder is already encoding to this command buffer' Thread 0:: Dispatch queue: com.apple.main-thread 0 DDNet 0x1021fcb40 IGraphics::ScreenWidth() const + 40 (graphics.h:205) 1 DDNet 0x10227c358 CTextRender::AppendTextContainer(CTextCursor*, int, char const*, int) + 728 (text.cpp:1078) 2 DDNet 0x10227c358 CTextRender::AppendTextContainer(CTextCursor*, int, char const*, int) + 728 (text.cpp:1078) 3 DDNet 0x10227bf1c CTextRender::CreateTextContainer(CTextCursor*, char const*, int) + 636 (text.cpp:978) 4 DDNet 0x10227bbdc CTextRender::TextEx(CTextCursor*, char const*, int) + 76 (text.cpp:909) 5 DDNet 0x10227f4d0 CTextRender::TextWidth(void*, float, char const*, int, float, float*, float*) + 188 (text.cpp:854) 6 DDNet 0x1023b2e30 CUI::DoTextLabel(float, float, float, float, char const*, float, int, float, int, bool, CTextCursor*) + 168 (ui.cpp:457) 7 DDNet 0x1023b30b4 CUI::DoLabel(CUIRect const*, char const*, float, int, float, int, CTextCursor*) + 132 (ui.cpp:509) 8 DDNet 0x10230598c CMenus::DoButton_GridHeader(void const*, char const*, int, CUIRect const*) + 344 (menus.cpp:321) 9 DDNet 0x102315300 CMenus::RenderServerbrowserServerList(CUIRect) + 2080 (menus_browser.cpp:153) 10 DDNet 0x10231bda0 CMenus::RenderServerbrowser(CUIRect) + 268 (menus_browser.cpp:1394) 11 DDNet 0x10230b4c8 CMenus::Render() + 1960 (menus.cpp:1408) 12 DDNet 0x1023101c8 CMenus::OnRender() + 1116 (menus.cpp:2534) 13 DDNet 0x102378038 CGameClient::OnRender() + 424 (gameclient.cpp:586) 14 DDNet 0x1021fd044 CClient::Render() + 252 (client.cpp:1171) 15 DDNet 0x102205c78 CClient::Run() + 3908 (client.cpp:3361) 16 DDNet 0x10220b70c TWMain + 2276 (client.cpp:4496) 17 DDNet 0x10229ef8c main + 256 (client.m:22) 18 dyld 0x102d790f4 start + 520 Thread 1: 0 libsystem_kernel.dylib 0x18b2c9f4c sem_wait + 8 1 DDNet 0x10219ccd4 sphore_wait + 44 (system.cpp:959) 2 DDNet 0x10219bcc8 aio_thread(void*) + 184 (system.cpp:522) 3 DDNet 0x10219ca40 thread_run(void*) + 84 (system.cpp:763) 4 libsystem_pthread.dylib 0x18b2d9240 _pthread_start + 148 5 libsystem_pthread.dylib 0x18b2d4024 thread_start + 8 Thread 2: 0 libsystem_kernel.dylib 0x18b2c9f4c sem_wait + 8 1 DDNet 0x10219ccd4 sphore_wait + 44 (system.cpp:959) 2 DDNet 0x102177e48 CJobPool::WorkerThread(void*) + 80 (jobs.cpp:64) 3 DDNet 0x10219ca40 thread_run(void*) + 84 (system.cpp:763) 4 libsystem_pthread.dylib 0x18b2d9240 _pthread_start + 148 5 libsystem_pthread.dylib 0x18b2d4024 thread_start + 8 Thread 3: 0 libsystem_kernel.dylib 0x18b2c9f4c sem_wait + 8 1 DDNet 0x10219ccd4 sphore_wait + 44 (system.cpp:959) 2 DDNet 0x102177e48 CJobPool::WorkerThread(void*) + 80 (jobs.cpp:64) 3 DDNet 0x10219ca40 thread_run(void*) + 84 (system.cpp:763) 4 libsystem_pthread.dylib 0x18b2d9240 _pthread_start + 148 5 libsystem_pthread.dylib 0x18b2d4024 thread_start + 8 Thread 4: 0 libsystem_pthread.dylib 0x18b2d4010 start_wqthread + 0 Thread 5: 0 libsystem_pthread.dylib 0x18b2d4010 start_wqthread + 0 Thread 6: 0 libsystem_pthread.dylib 0x18b2d4010 start_wqthread + 0 Thread 7 Crashed: 0 libsystem_kernel.dylib 0x18b2a59b8 __pthread_kill + 8 1 libsystem_pthread.dylib 0x18b2d8eb0 pthread_kill + 288 2 libsystem_c.dylib 0x18b216314 abort + 164 3 libsystem_c.dylib 0x18b2156d4 __assert_rtn + 212 4 Metal 0x193c29d50 MTLReportFailure.cold.1 + 56 5 Metal 0x193c13d04 MTLReportFailure + 476 6 AGXMetalG13X 0x1d0afcd34 0x1d0908000 + 2051380 7 AppleMetalOpenGLRenderer 0x10bc78098 GLDContextRec::beginRenderPass() + 136 8 AppleMetalOpenGLRenderer 0x10bc8f6c0 gldRenderVertexArray(GLDContextRec*, unsigned int, unsigned int, int, int, unsigned int, void const*, int, void const*) + 492 9 GLEngine 0x1ec997338 glDrawElements_GL3Exec + 296 10 DDNet 0x1021d82a8 CCommandProcessorFragment_OpenGL3_3::Cmd_RenderQuadLayer(CCommandBuffer::SCommand_RenderQuadLayer const*) + 828 (backend_opengl3.cpp:1281) 11 DDNet 0x1021c1178 CCommandProcessorFragment_OpenGL::RunCommand(CCommandBuffer::SCommand const*) + 984 (backend_opengl.cpp:1086) 12 DDNet 0x1021ec2e4 CCommandProcessor_SDL_OpenGL::RunBuffer(CCommandBuffer*) + 88 (backend_sdl.cpp:221) 13 DDNet 0x1021eb384 CGraphicsBackend_Threaded::ThreadFunc() + 144 (backend_sdl.cpp:72) 14 DDNet 0x1021f6138 CGraphicsBackend_Threaded::StartProcessor(CGraphicsBackend_Threaded::ICommandProcessor*)::$_0::operator()() const + 44 (backend_sdl.cpp:97) 15 DDNet 0x1021f6034 decltype(std::__1::forwardFailed assertion is:
Might be related to https://github.com/libsdl-org/SDL/pull/4242 which happend previously, but this crash still happens with SDL 2.0.18.
Similar issues seem to exist on GLFW, see https://github.com/glfw/glfw/issues/1997