diff --git a/src/core/sceneSetup.ts b/src/core/sceneSetup.ts index 3ea3509..b22a7b8 100644 --- a/src/core/sceneSetup.ts +++ b/src/core/sceneSetup.ts @@ -37,6 +37,8 @@ export async function setupScene( const audioEngine = await createAudioEngine(); reporter.reportProgress(30, 'Audio engine ready'); + // Stop any existing render loop before starting new one (prevents doubling on reload) + engine.stopRenderLoop(); engine.runRenderLoop(() => DefaultScene.MainScene.render()); return { engine, audioEngine }; @@ -50,6 +52,10 @@ function createEngine(canvas: HTMLCanvasElement): Engine { } function createMainScene(engine: Engine): void { + // Dispose old scene if it exists (prevents doubling on reload) + if (DefaultScene.MainScene && !DefaultScene.MainScene.isDisposed) { + DefaultScene.MainScene.dispose(); + } DefaultScene.MainScene = new Scene(engine); DefaultScene.MainScene.ambientColor = new Color3(.2, .2, .2); DefaultScene.MainScene.clearColor = new Color3(0, 0, 0).toColor4(); diff --git a/src/ship/input/keyboardInput.ts b/src/ship/input/keyboardInput.ts index 21682d0..934d5ab 100644 --- a/src/ship/input/keyboardInput.ts +++ b/src/ship/input/keyboardInput.ts @@ -100,15 +100,17 @@ export class KeyboardInput { document.onkeydown = (ev) => { // Always allow inspector and camera toggle, even when disabled if (ev.key === 'i') { - // Toggle Babylon Inspector - if (this._scene.debugLayer.isVisible()) { - this._scene.debugLayer.hide(); - } else { - this._scene.debugLayer.show({ - overlay: true, - showExplorer: true, - }); - } + // Dynamically import inspector on first use (keeps it out of main bundle) + import('@babylonjs/inspector').then(() => { + if (this._scene.debugLayer.isVisible()) { + this._scene.debugLayer.hide(); + } else { + this._scene.debugLayer.show({ + overlay: true, + showExplorer: true, + }); + } + }); return; }