From 63a75bc0eaa36e0cd0f928f4710ebe1ef6ffe90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 30 Jun 2026 22:31:36 -0700 Subject: [PATCH] Fixed s_renderFrameCalled cleanup. (#3804) --- src/bgfx.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index ee1fd33cb..502e2be30 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2518,14 +2518,26 @@ namespace bgfx #if BGFX_CONFIG_MULTITHREADED // Render thread shutdown sequence. renderSemWait(); // Wait for previous frame. - apiSemPost(); // OK to set context to NULL. + apiSemPost(); // OK to set context to NULL. // s_ctx is NULL here. renderSemWait(); // In RenderFrame::Exiting state. if (m_thread.isRunning() ) { - s_renderFrameCalled = false; m_thread.shutdown(); + + // Internal render thread was created it owns the latch, clear it as the thread exits. + s_renderFrameCalled = false; + } + else if (m_singleThreaded) + { + // bgfx::renderFrame() was latched on API thread. + s_renderFrameCalled = false; + } + else + { + // Otherwise bgfx::renderFrame() was called manually, and latched on different thread. + // So we don't control it... } m_render->destroy();