diff --git a/CHANGELOG.md b/CHANGELOG.md index a111d362a..529346c82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fixed issue where adding scenes with the same name did not work when it was previously removed - Fixed issue when WebGL context lost occurs where there was no friendly output to the user - Fixed issue where HiDPI scaling could accidentally scale past the 4k mobile limit, if the context would scale too large it will now attempt to recover by backing off. - Fixed issue where logo was sometimes not loaded during `ex.Loader` diff --git a/src/engine/Director/Director.ts b/src/engine/Director/Director.ts index 42a2e8a6d..6f14f1341 100644 --- a/src/engine/Director/Director.ts +++ b/src/engine/Director/Director.ts @@ -350,6 +350,7 @@ export class Director { throw new Error(`Cannot remove a currently active scene: ${key}`); } + this._sceneToInstance.delete(key); this._sceneToTransition.delete(key); this._sceneToLoader.delete(key); delete this.scenes[key as TKnownScenes]; @@ -363,6 +364,7 @@ export class Director { } // remove scene + this._sceneToInstance.delete(nameOrScene); this._sceneToTransition.delete(nameOrScene); this._sceneToLoader.delete(nameOrScene); delete this.scenes[nameOrScene as TKnownScenes]; diff --git a/src/spec/DirectorSpec.ts b/src/spec/DirectorSpec.ts index c977c4e2f..24f187fa0 100644 --- a/src/spec/DirectorSpec.ts +++ b/src/spec/DirectorSpec.ts @@ -194,6 +194,29 @@ describe('A Director', () => { expect(() => sut.remove(sut.rootScene)).toThrowError('Cannot remove a currently active scene: root'); }); + it('can add a scene that was already deleted', async () => { + const engine = TestUtils.engine(); + const clock = engine.clock as ex.TestClock; + clock.start(); + const scene1 = new ex.Scene(); + const scene2 = new ex.Scene(); + const sut = new ex.Director(engine, { + scene1, + scene2 + }); + sut.configureStart('scene1'); + sut.onInitialize(); + await sut.goto('scene2'); + expect(sut.currentScene).toBe(scene2); + sut.remove('scene1'); + + const newScene = new ex.Scene(); + sut.add('scene1', newScene); + + await sut.goto('scene1'); + expect(sut.currentScene).toBe(newScene); + }); + it('can goto a scene', async () => { const engine = TestUtils.engine(); const clock = engine.clock as ex.TestClock;