Skip to content

Commit fa2b781

Browse files
committed
The CameraManager was accidentally adding extra destroy event calls when a Scene was restarted, causing an Uncaught TypeError: Cannot read property 'events' of null when trying to destroy a game instance having swapped from a Scene to another, and back again. Fix phaserjs#3878
1 parent d0f3d85 commit fa2b781

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ The process of managing scissors in the WebGLRenderer has been completely rewrit
6060
* In ArcadePhysics `Body.setSize` you can now choose to not pass width and height values to the method. If you do this it will check to see if the parent Game Object has a texture frame, and if so, it will use the frame sizes for the Body dimensions (thanks @tarsupin)
6161
* `PluginCache.destroyCorePlugins` will remove all core plugins from the cache. Be very careful calling this as Phaser cannot restart or create any new Scenes once this has been called.
6262
* `PluginCache.destroyCustomPlugins` will remove all custom plugins from the cache.
63-
* `PluginManager.destroy` will now clear all custom plugins from the Plugin Cache. This fixes an issue with not being able to destroy a Phaser game instance and restart it if it used a custom plugin.
63+
* `PluginManager.destroy` will now clear all custom plugins from the Plugin Cache. This fixes an issue with not being able to destroy a Phaser game instance and restart it if it used a custom plugin (thanks jd.joshuadavison)
6464
* `Game.destroy` has a new boolean argument `noReturn`. If set it will remove all Core plugins when the game instance is destroyed. You cannot restart Phaser on the same web page after doing this, so only set it if you know you're done and don't need to run Phaser again.
65+
* The `MouseManager` will no longer process its native events if the manager reference has been removed (i.e. you move the pointer as the game is destroying itself)
66+
* The `TouchManager` will no longer process its native events if the manager reference has been removed (i.e. you move the pointer as the game is destroying itself)
6567

6668
### Game Config Resolution Specific Bug Fixes
6769

@@ -89,6 +91,7 @@ Setting the `resolution` property in the Game Config to a value other than 1 wou
8991
* `RenderTexture.preDestroy` will now release the canvas back to the CanvasPool if running in canvas mode (thanks @SBCGames)
9092
* The `alpha` value is now always set for Render Textures in canvas mode, regardless of the previous alpha value in the renderer (thanks @SBCGames)
9193
* Zone now calls `updateDisplayOrigin` in its constructor, causing the `displayOriginX` and `displayOriginY` values to now be correct if you create a Zone and then don't resize it. Fix #3865 (thanks @rexrainbow)
94+
* The `CameraManager` was accidentally adding extra destroy event calls when a Scene was restarted, causing an `Uncaught TypeError: Cannot read property 'events' of null` when trying to destroy a game instance having swapped from a Scene to another, and back again. Fix #3878 (thanks @mbunby)
9295

9396
### Examples, Documentation and TypeScript
9497

src/cameras/2d/CameraManager.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,20 @@ var CameraManager = new Class({
188188
{
189189
if (!this.main)
190190
{
191-
this.boot();
191+
var sys = this.systems;
192+
193+
if (sys.settings.cameras)
194+
{
195+
// We have cameras to create
196+
this.fromJSON(sys.settings.cameras);
197+
}
198+
else
199+
{
200+
// Make one
201+
this.add();
202+
}
203+
204+
this.main = this.cameras[0];
192205
}
193206

194207
var eventEmitter = this.systems.events;

0 commit comments

Comments
 (0)