Skip to content

Commit

Permalink
Fix NativeEngine memory leak (#104)
Browse files Browse the repository at this point in the history
* Actually dispose engine in release builds
* Bring in XMLHttpRequest fixes for BabylonNative
  • Loading branch information
ryantrem authored Oct 28, 2020
1 parent 4ed730e commit 19e9cdf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions Modules/@babylonjs/react-native/EngineHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}, []);

Expand Down

0 comments on commit 19e9cdf

Please sign in to comment.