From f22caf2719bc241c2c1854b3f56891c815ca3d78 Mon Sep 17 00:00:00 2001 From: 0xmugen Date: Wed, 9 Oct 2024 15:25:25 +0200 Subject: [PATCH] feat: add some logging --- client/src/lib/3d/Scene.svelte | 13 ++++++++++--- client/src/lib/3d/utils/shootUtils.ts | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client/src/lib/3d/Scene.svelte b/client/src/lib/3d/Scene.svelte index 2d9fb52e..a94f499d 100644 --- a/client/src/lib/3d/Scene.svelte +++ b/client/src/lib/3d/Scene.svelte @@ -67,12 +67,16 @@ const animationLoop = () => { try { if ($birdView) { - if (birdViewCamera) { + if (birdViewCamera && birdViewCamera.isCamera) { resetCamera(birdViewCamera, renderer) - renderer.render(scene, birdViewCamera) + if (scene && scene.isScene) { + renderer.render(scene, birdViewCamera) + } } } else { - renderCameras(cameras, numCameras, renderer, scene) + if (cameras.length > 0 && cameras.every(cam => cam && cam.isCamera)) { + renderCameras(cameras, numCameras, renderer, scene) + } } if ($recordingMode) { @@ -94,6 +98,9 @@ animationFrameId = requestAnimationFrame(animationLoop) } catch (error) { console.error('Error in animation loop:', error) + if (error instanceof TypeError && error.message.includes('byteLength')) { + console.warn('Possible issue with buffer or geometry.') + } } } diff --git a/client/src/lib/3d/utils/shootUtils.ts b/client/src/lib/3d/utils/shootUtils.ts index 7480c698..74236413 100644 --- a/client/src/lib/3d/utils/shootUtils.ts +++ b/client/src/lib/3d/utils/shootUtils.ts @@ -33,6 +33,11 @@ function applyBulletToStore(newBullet: BulletCoords) { } export function shoot(camera: PerspectiveCamera) { + if (!camera || !camera.isCamera) { + console.error('Invalid camera object') + return + } + let move_index = Math.floor(get(frameCounter) / 3) let direction = getYawAngle(camera) @@ -47,6 +52,10 @@ export function shoot(camera: PerspectiveCamera) { ) recordedMove.update((rm) => { + if (!rm || !Array.isArray(rm.shots)) { + console.error('Invalid recordedMove structure') + return rm + } rm.shots.push({ angle: direction, step: move_index }) console.log(rm.shots) return rm