dev: better crash report

This commit is contained in:
cha0s 2024-09-28 11:27:44 -05:00
parent b5019153f3
commit f328ce4ccb

View File

@ -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 () => {
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();