excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.82k stars 189 forks source link

unused scene loader fails scene transitions and locks up engine #3128

Closed andybarron closed 3 months ago

andybarron commented 4 months ago

Steps to Reproduce

import * as ex from "excalibur";

class Scene1 extends ex.Scene {
  override backgroundColor = ex.Color.DarkGray;
  override onInitialize() {
    this.input.pointers.on("down", () => {
      console.warn("should change scenes");
      this.engine.goToScene("Scene2");
    });
  }
}

class Scene2 extends ex.Scene {
  override backgroundColor = ex.Color.Viridian;
  // issue still occurs if onPreLoad is not defined or
  // if we call super.onPreLoad(loader)
  override onPreLoad(loader: ex.DefaultLoader) {
    // un-commenting this call fixes the issue.
    // loader.addResource({
    //   data: {},
    //   isLoaded: () => true,
    //   load: () => Promise.resolve(),
    // });
  }
}

const game = new ex.Engine({
  scenes: {
    Scene1,
    Scene2: { scene: Scene2, loader: ex.Loader },
  },
});

game.start();
game.goToScene("Scene1");

Expected Result

Actual Result

Environment

Current Workaround

Adding a fake resource to the loader fixes the issue.

eonarheim commented 4 months ago

@andybarron Woof definitely unexpected! Nice find!

Theoretically should be a quick fix