JS thread deadlocks in NativeEngine::SubmitCommands when an engine is disposed and a new one created quickly

Open
#773 0 comments 0 reactions 0 assignees View on GitHub

@CedricGuillemet is already working on this.

Since Dec 2, 2026.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
47/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, react-native
Domain
backend, mobile

Research direction

Start in NativeEngine.cpp at SubmitCommands (around line 4005), then trace DeviceContext.cpp's AcquireFrameCompletionScope and the ReactNativeEngine.dispose/reset path described in the report. Reproduce by rapidly unmounting and remounting EngineView after its first frame, and inspect how asynchronous resetView interacts with rendering. Done means the new engine renders reliably after repeated quick remounts.

Written by the indexing model from the issue text.

Description

Environment: @babylonjs/react-native 2.0.7 (Babylon Native f4d9efb), React Native 0.81.6 (legacy architecture), Hermes, Xcode 27.1, iOS 27.0 Simulator (iPhone 17), macOS 27.0.1.

Steps

  1. A component calls useEngine() and renders <EngineView camera={…} /> with a non-trivial scene (shadows, glow,
    GUI).
  2. Unmount it and mount a fresh instance (new useEngine(), new EngineView) several times in quick succession.
    Re-mounting within about 1 s of the previous scene's first frame is enough.

Expected: the new engine renders.

Actual: the app freezes at 0% CPU. No crash report is written. The JS thread blocks forever:

Babylon::NativeEngine::SubmitCommands(Napi::CallbackInfo const&)            NativeEngine.cpp:4005
Babylon::Graphics::DeviceContext::AcquireFrameCompletionScope()             DeviceContext.cpp:67
Babylon::Graphics::FrameCompletionScope::FrameCompletionScope(DeviceImpl&)  DeviceContext.cpp:47
Babylon::Graphics::DeviceImpl::IncrementPendingFrameScopes()                DeviceImpl.cpp:525
std::condition_variable::wait(std::unique_lock<std::mutex>&)

This reproduces in both Debug and Release. Likely cause: ReactNativeEngine.dispose() → reset() →
BabylonModule.resetView() runs asynchronously, so it can land after the new view has re-enabled rendering. The new
engine then submits into a device that never starts another frame.

Workaround: keep one engine and one EngineView for the app lifetime and dispose only scenes. An extra scene with
autoClear = false keeps frames flowing when no "real" scene is shown.

Dominant language
C++
Stars
437
Forks
72
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from BabylonJS/BabylonReactNative

All issues in BabylonJS/BabylonReactNative

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.