Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
flyskywhy committed Dec 11, 2022
1 parent da4943c commit 83aa182
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/react-babylonjs/src/Engine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const ReactBabylonjsEngine: React.FC<EngineProps> = (props: EngineProps, context
const onEndRenderLoopObservable = useRef<Observable<Engine>>(new Observable<Engine>())

const canvasRef = useRef<Nullable<HTMLCanvasElement>>(null)
const [canvasReady, setCanvasReady] = useState(false)
const shouldRenderRef = useRef(true)

// const renderOptions: RenderOptions = props.renderOptions ?? {};
Expand All @@ -118,6 +119,10 @@ const ReactBabylonjsEngine: React.FC<EngineProps> = (props: EngineProps, context
}, [isPaused])

useEffect(() => {
if (!canvasReady) {
return;
}

if (canvasRef.current === null) {
return
}
Expand Down Expand Up @@ -183,7 +188,7 @@ const ReactBabylonjsEngine: React.FC<EngineProps> = (props: EngineProps, context
engine.current = null
}
}
}, [canvasRef])
}, [canvasReady])

const opts: any = {}

Expand All @@ -202,7 +207,7 @@ const ReactBabylonjsEngine: React.FC<EngineProps> = (props: EngineProps, context
<canvas
{...opts}
{...canvasProps}
ref={canvasRef}
ref={(view) => {canvasRef.current = view; setCanvasReady(true)}}
style={{ width: '100%', height: '100%', ...style }}
>
{engine.current !== null && props.children}
Expand Down

0 comments on commit 83aa182

Please sign in to comment.