Skip to content

Commit 3049774

Browse files
authored
Protect against accidentally re-enabling graphics during teardown (#249)
1 parent 698c81e commit 3049774

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Modules/@babylonjs/react-native/shared/BabylonNative.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ namespace Babylon
7979
}
8080

8181
g_graphics->EnableRendering();
82+
m_isRenderingEnabled = true;
8283

8384
std::call_once(m_isGraphicsInitialized, [this]()
8485
{
@@ -97,7 +98,9 @@ namespace Babylon
9798

9899
void RenderView()
99100
{
100-
if (g_graphics)
101+
// If rendering has not been explicitly enabled, or has been explicitly disabled, then don't try to render.
102+
// Otherwise rendering can be implicitly enabled, which may not be desirable (e.g. after the engine is disposed).
103+
if (g_graphics && m_isRenderingEnabled)
101104
{
102105
g_graphics->StartRenderingCurrentFrame();
103106
g_graphics->FinishRenderingCurrentFrame();
@@ -115,6 +118,8 @@ namespace Babylon
115118
CreateInitPromise();
116119
});
117120
}
121+
122+
m_isRenderingEnabled = false;
118123
}
119124

120125
void SetMouseButtonState(uint32_t buttonId, bool isDown, uint32_t x, uint32_t y)
@@ -198,6 +203,7 @@ namespace Babylon
198203
Dispatcher m_jsDispatcher{};
199204

200205
std::shared_ptr<bool> m_isRunning{};
206+
bool m_isRenderingEnabled{};
201207
std::once_flag m_isGraphicsInitialized{};
202208
Plugins::NativeInput* m_nativeInput{};
203209
std::optional<Plugins::NativeXr> m_nativeXr{};

0 commit comments

Comments
 (0)