`engine.runRenderLoop()` still called after stopping & disposing it—resulting in an attempt to read a null property

I implemented the changes you suggested, but sadly, that didn’t resolve the problem. I get the same error, except now the new scene doesn’t load at all.

The new code:

const engine = new Engine(canvas);
let currentScene: Scene;

function SetScene(
  newScene: SceneType,
  enteringFromMall: boolean = false
): void {
  const oldScene = currentScene;

  switch (newScene) {
    case SceneType.Main:
      const main = new main(engine, streamUrl, SetScene, enteringFromMall);
      currentScene = main.scene;
      break;
    case SceneType.Mall:
      const mall = new ShoppingMall(engine, SetScene);
      currentScene = mall.scene;
      break;
  }

  if (oldScene) oldScene.dispose();
}

// Set up the first scene.
SetScene(SceneType.Main);
engine.runRenderLoop(() => currentScene.render());

If I comment out the last line—if (oldScene) oldScene.dispose()—I get a different error:

Uncaught TypeError: Cannot read properties of undefined (reading '0')
    at deviceInputSystem.js:212:58

The scene loads in this case, but of course, that leaves the previous scene running. Not ideal. :tired_face:

Any ideas?