From cceedb60cfe43dcde9786949e3beeef9b1da2944 Mon Sep 17 00:00:00 2001 From: ShuangLiu1992 Date: Sun, 26 Apr 2026 04:15:29 +0100 Subject: [PATCH] Fix: reset s_renderFrameCalled in bgfx::shutdown() to allow re-init (#3690) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bgfx::renderFrame() sets s_renderFrameCalled = true on its first call (line 1541) and never clears it. bgfx::shutdown() resets s_threadIndex to 0 (line 3958) but leaves s_renderFrameCalled sticky, which means that on a 2nd renderFrame after shutdown the gate at line 1534 still runs BGFX_CHECK_RENDER_THREAD(). That assertion checks (s_ctx != NULL && single-threaded) || (~BGFX_API_THREAD_MAGIC == s_threadIndex); both branches fail post-shutdown (s_ctx is NULL, s_threadIndex is 0), and the assertion fires in debug builds — blocking re-init of the bgfx context within the same process. Adding the symmetric s_renderFrameCalled reset to shutdown() makes shutdown leave bgfx in the same state as a fresh process, so a subsequent renderFrame()+init() pair behaves like the first one. Verified locally: a downstream test that constructs an SDL+bgfx context, runs a frame, destroys it, then constructs another from the same thread now passes in debug builds with this patch (it asserts at line 1536 without it). --- src/bgfx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 69a3b4443..471583429 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -3956,6 +3956,7 @@ namespace bgfx } s_threadIndex = 0; + s_renderFrameCalled = false; g_callback = NULL; g_allocator = NULL; }