From 08bc7c393c9015e07c0ef83ea2d0a34f9baade3d Mon Sep 17 00:00:00 2001 From: Brian Zinn Date: Sat, 30 May 2020 17:46:00 -0700 Subject: [PATCH] Engine unmounted first and Engine dispose() disposes of the Scene. Need an additional check before disposing the Scene #65 --- src/Engine.tsx | 5 +++-- src/Scene.tsx | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Engine.tsx b/src/Engine.tsx index 993c30b3..bcbd6b24 100644 --- a/src/Engine.tsx +++ b/src/Engine.tsx @@ -136,8 +136,9 @@ class Engine extends React.Component { componentWillUnmount () { window.removeEventListener('resize', this.onResizeWindow); - if (this.engine != null) { - this.engine?.dispose(); + + if (this.engine !== null) { + this.engine!.dispose(); this.engine = null; } } diff --git a/src/Scene.tsx b/src/Scene.tsx index 52a88dec..a996da23 100644 --- a/src/Scene.tsx +++ b/src/Scene.tsx @@ -223,7 +223,9 @@ const Scene: React.FC = (props: SceneProps, context?: any) => { scene.onPointerObservable.remove(pointerMoveObservable); } - scene.dispose(); + if (scene.isDisposed === false) { + scene.dispose(); + } } }, [/* no deps, so called only on un/mount */]