diff --git a/Modules/@babylonjs/react-native/EngineHook.ts b/Modules/@babylonjs/react-native/EngineHook.ts index 5ff3df80e..e3b20156f 100644 --- a/Modules/@babylonjs/react-native/EngineHook.ts +++ b/Modules/@babylonjs/react-native/EngineHook.ts @@ -67,22 +67,23 @@ export function useEngine(): Engine | undefined { useEffect(() => { let disposed = false; + let engine: Engine | undefined = undefined; (async () => { if (await BabylonModule.initialize() && !disposed) { - setEngine(new NativeEngine()); + engine = new NativeEngine(); + setEngine(engine); } })(); return () => { disposed = true; - setEngine(engine => { - if (engine) { - DisposeEngine(engine); - } - return undefined; - }); + // NOTE: Do not use setEngine with a callback to dispose the engine instance as that callback does not get called during component unmount when compiled in release. + if (engine) { + DisposeEngine(engine); + } + setEngine(undefined); }; }, []); diff --git a/Modules/@babylonjs/react-native/submodules/BabylonNative b/Modules/@babylonjs/react-native/submodules/BabylonNative index e81f65f12..f2d2717bc 160000 --- a/Modules/@babylonjs/react-native/submodules/BabylonNative +++ b/Modules/@babylonjs/react-native/submodules/BabylonNative @@ -1 +1 @@ -Subproject commit e81f65f129e5f93a343ab79e0fc93a18f4f10899 +Subproject commit f2d2717bc09739acc7db6ed8ef48875979e02b6f