Fix scene doubling on reload and add dynamic inspector import
All checks were successful
Build / build (push) Successful in 1m45s
All checks were successful
Build / build (push) Successful in 1m45s
- Dispose old scene before creating new one (cleans up physics) - Stop existing render loop before starting new one - Dynamically import @babylonjs/inspector on 'i' key press 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
dfa46c85a6
commit
cf3a74ff0b
@ -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();
|
||||
|
||||
@ -100,7 +100,8 @@ export class KeyboardInput {
|
||||
document.onkeydown = (ev) => {
|
||||
// Always allow inspector and camera toggle, even when disabled
|
||||
if (ev.key === 'i') {
|
||||
// Toggle Babylon Inspector
|
||||
// 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 {
|
||||
@ -109,6 +110,7 @@ export class KeyboardInput {
|
||||
showExplorer: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user