mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 22:18:29 +00:00
If a Game instance is destroyed without using the removeCanvas
argument, it would throw exceptions in the MouseManager
after the destroy process has run, as the event listeners were not unbound. They're not unbound, regardless of if the parent canvas is removed or not. Fix #4015
This commit is contained in:
parent
faaadb357e
commit
b3f3f6a9b5
3 changed files with 83 additions and 19 deletions
|
@ -72,6 +72,7 @@
|
|||
* When using `CanvasTexture.refresh` or `Graphics.generateTexture` it would throw WebGL warnings like 'bindTexture: Attempt to bind a deleted texture'. This was due to the Frames losing sync with the glTexture reference used by their TextureSource. Fix #4050 (thanks @kanthi0802)
|
||||
* Fixed an error in the `batchSprite` methods in the Canvas and WebGL Renderers that would incorrectly set the frame dimensions on Sprites with the crop component. This was particularly noticeable on Sprites with trimmed animation frames (thanks @sergeod9)
|
||||
* Fixed a bug where the gl scissor wasn't being reset during a renderer resize, causing it to appear as if the canvas didn't resize properly when `autoResize` was set to `true` in the game config. Fix #4066 (thanks @Quinten @hsan999)
|
||||
* If a Game instance is destroyed without using the `removeCanvas` argument, it would throw exceptions in the `MouseManager` after the destroy process has run, as the event listeners were not unbound. They're not unbound, regardless of if the parent canvas is removed or not. Fix #4015 (thanks @garethwhittaker)
|
||||
|
||||
### Examples and TypeScript
|
||||
|
||||
|
|
|
@ -172,6 +172,8 @@ var MouseManager = new Class({
|
|||
*
|
||||
* @param {MouseEvent} event - The native event from the browser.
|
||||
*/
|
||||
|
||||
/*
|
||||
pointerLockChange: function (event)
|
||||
{
|
||||
var element = this.target;
|
||||
|
@ -180,6 +182,7 @@ var MouseManager = new Class({
|
|||
|
||||
this.manager.queue.push(event);
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* If the browser supports pointer lock, this will request that the pointer lock is released. If
|
||||
|
@ -206,6 +209,8 @@ var MouseManager = new Class({
|
|||
*
|
||||
* @param {MouseEvent} event - The native DOM Mouse Move Event.
|
||||
*/
|
||||
|
||||
/*
|
||||
onMouseMove: function (event)
|
||||
{
|
||||
if (event.defaultPrevented || !this.enabled || !this.manager)
|
||||
|
@ -221,6 +226,7 @@ var MouseManager = new Class({
|
|||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Mouse Down Event Handler.
|
||||
|
@ -230,6 +236,8 @@ var MouseManager = new Class({
|
|||
*
|
||||
* @param {MouseEvent} event - The native DOM Mouse Down Event.
|
||||
*/
|
||||
|
||||
/*
|
||||
onMouseDown: function (event)
|
||||
{
|
||||
if (event.defaultPrevented || !this.enabled)
|
||||
|
@ -245,6 +253,7 @@ var MouseManager = new Class({
|
|||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Mouse Up Event Handler.
|
||||
|
@ -254,6 +263,8 @@ var MouseManager = new Class({
|
|||
*
|
||||
* @param {MouseEvent} event - The native DOM Mouse Up Event.
|
||||
*/
|
||||
|
||||
/*
|
||||
onMouseUp: function (event)
|
||||
{
|
||||
if (event.defaultPrevented || !this.enabled)
|
||||
|
@ -269,6 +280,7 @@ var MouseManager = new Class({
|
|||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* Starts the Mouse Event listeners running.
|
||||
|
@ -279,31 +291,84 @@ var MouseManager = new Class({
|
|||
*/
|
||||
startListeners: function ()
|
||||
{
|
||||
var target = this.target;
|
||||
var _this = this;
|
||||
|
||||
var onMouseMove = function (event)
|
||||
{
|
||||
if (event.defaultPrevented || !_this.enabled || !_this.manager)
|
||||
{
|
||||
// Do nothing if event already handled
|
||||
return;
|
||||
}
|
||||
|
||||
_this.manager.queueMouseMove(event);
|
||||
|
||||
if (_this.capture)
|
||||
{
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
var onMouseDown = function (event)
|
||||
{
|
||||
if (event.defaultPrevented || !_this.enabled || !_this.manager)
|
||||
{
|
||||
// Do nothing if event already handled
|
||||
return;
|
||||
}
|
||||
|
||||
_this.manager.queueMouseDown(event);
|
||||
|
||||
if (_this.capture)
|
||||
{
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
var onMouseUp = function (event)
|
||||
{
|
||||
if (event.defaultPrevented || !_this.enabled || !_this.manager)
|
||||
{
|
||||
// Do nothing if event already handled
|
||||
return;
|
||||
}
|
||||
|
||||
_this.manager.queueMouseUp(event);
|
||||
|
||||
if (_this.capture)
|
||||
{
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
this.onMouseMove = onMouseMove;
|
||||
this.onMouseDown = onMouseDown;
|
||||
this.onMouseUp = onMouseUp;
|
||||
|
||||
var target = this.target;
|
||||
var passive = { passive: true };
|
||||
var nonPassive = { passive: false };
|
||||
|
||||
if (this.capture)
|
||||
{
|
||||
target.addEventListener('mousemove', this.onMouseMove.bind(this), nonPassive);
|
||||
target.addEventListener('mousedown', this.onMouseDown.bind(this), nonPassive);
|
||||
target.addEventListener('mouseup', this.onMouseUp.bind(this), nonPassive);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.addEventListener('mousemove', this.onMouseMove.bind(this), passive);
|
||||
target.addEventListener('mousedown', this.onMouseDown.bind(this), passive);
|
||||
target.addEventListener('mouseup', this.onMouseUp.bind(this), passive);
|
||||
}
|
||||
target.addEventListener('mousemove', onMouseMove, (this.capture) ? nonPassive : passive);
|
||||
target.addEventListener('mousedown', onMouseDown, (this.capture) ? nonPassive : passive);
|
||||
target.addEventListener('mouseup', onMouseUp, (this.capture) ? nonPassive : passive);
|
||||
|
||||
if (Features.pointerLock)
|
||||
{
|
||||
this.pointerLockChange = this.pointerLockChange.bind(this);
|
||||
var onPointerLockChange = function (event)
|
||||
{
|
||||
var element = _this.target;
|
||||
|
||||
document.addEventListener('pointerlockchange', this.pointerLockChange, true);
|
||||
document.addEventListener('mozpointerlockchange', this.pointerLockChange, true);
|
||||
document.addEventListener('webkitpointerlockchange', this.pointerLockChange, true);
|
||||
_this.locked = (document.pointerLockElement === element || document.mozPointerLockElement === element || document.webkitPointerLockElement === element) ? true : false;
|
||||
|
||||
_this.manager.queue.push(event);
|
||||
};
|
||||
|
||||
this.pointerLockChange = onPointerLockChange;
|
||||
|
||||
document.addEventListener('pointerlockchange', onPointerLockChange, true);
|
||||
document.addEventListener('mozpointerlockchange', onPointerLockChange, true);
|
||||
document.addEventListener('webkitpointerlockchange', onPointerLockChange, true);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -568,8 +568,6 @@ var WebGLRenderer = new Class({
|
|||
|
||||
this.resize(this.width, this.height);
|
||||
|
||||
console.log(this.config);
|
||||
|
||||
this.game.events.once('texturesready', this.boot, this);
|
||||
|
||||
return this;
|
||||
|
|
Loading…
Add table
Reference in a new issue