diff --git a/app/react/components/ui.jsx b/app/react/components/ui.jsx index 82b277d..aaac9f0 100644 --- a/app/react/components/ui.jsx +++ b/app/react/components/ui.jsx @@ -232,12 +232,18 @@ function Ui({disconnected}) { ]); usePacket('EcsChange', onEcsChangePacket); const onTickPacket = useCallback(async (payload, client) => { - if (0 === Object.keys(payload.ecs).length) { + if (!ecsRef.current || 0 === Object.keys(payload.ecs).length) { return; } latestTick.current = Promise.resolve(latestTick.current).then(async () => { - await ecsRef.current.apply(payload.ecs); - client.emitter.invoke(':Ecs', payload.ecs); + try { + await ecsRef.current.apply(payload.ecs); + client.emitter.invoke(':Ecs', payload.ecs); + } + catch (error) { + ecsRef.current = undefined; + console.error('tick crash', error); + } }); }, [ecsRef]); usePacket('Tick', onTickPacket); @@ -361,7 +367,7 @@ function Ui({disconnected}) { }; }, []); const computePosition = useCallback(({clientX, clientY}) => { - if (!gameRef.current || !mainEntityRef.current) { + if (!gameRef.current || !mainEntityRef.current || !ecsRef.current) { return; } const {top, left, width} = gameRef.current.getBoundingClientRect();