Skip to content

Commit

Permalink
Clean destroy xeolabs#327 pull request
Browse files Browse the repository at this point in the history
fixed memory leaks and new build
  • Loading branch information
mhoelzner committed Mar 26, 2020
1 parent 0c7d131 commit c062a44
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 50 deletions.
39 changes: 22 additions & 17 deletions build/xeogl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* WebGL-based 3D visualization library
* http://xeogl.org/
*
* Built on 2020-03-06
* Built on 2020-03-26
*
* MIT License
* Copyright 2020, Lindsay Kay
Expand Down Expand Up @@ -6218,6 +6218,12 @@ class Component {

this.scene._removeComponent(this);

/**
* Fired when this Component is destroyed.
* @event destroyed
*/
this.fire("destroyed", this.destroyed = true);

// Memory leak avoidance
this._attached = {};
this._attachments = null;
Expand All @@ -6229,11 +6235,6 @@ class Component {
this._adoptees = null;
this._updateScheduled = false;

/**
* Fired when this Component is destroyed.
* @event destroyed
*/
this.fire("destroyed", this.destroyed = true);
}
}

Expand Down Expand Up @@ -21650,26 +21651,26 @@ class Input extends Component {
}

destroy() {
super.destroy();
// Prevent memory leak when destroying canvas/WebGL context
document.removeEventListener("keydown", this._keyDownListener);
document.removeEventListener("keydown", this._keyDownListener, true);
document.removeEventListener("keyup", this._keyUpListener);
this._element.removeEventListener("mouseenter", this._mouseEnterListener);
this._element.removeEventListener("mouseleave", this._mouseLeaveListener);
this._element.removeEventListener("mousedown", this._mouseDownListener);
document.removeEventListener("mouseup", this._mouseDownListener);
document.removeEventListener("mouseup", this._mouseUpListener, true);
document.removeEventListener("dblclick", this._dblClickListener);
this._element.removeEventListener("mousemove", this._mouseMoveListener);
this._element.removeEventListener("wheel", this._mouseWheelListener);
if (window.OrientationChangeEvent) {
window.removeEventListener('orientationchange', this._orientationchangedListener);
window.removeEventListener('orientationchange', this._orientationchangedListener, false);
}
if (window.DeviceMotionEvent) {
window.removeEventListener('devicemotion', this._deviceMotionListener);
window.removeEventListener('devicemotion', this._deviceMotionListener, false);
}
if (window.DeviceOrientationEvent) {
window.addEventListener("deviceorientation", this._deviceOrientListener);
window.removeEventListener("deviceorientation", this._deviceOrientListener, false);
}
super.destroy();
}
}

Expand Down Expand Up @@ -28022,7 +28023,7 @@ const core = {
scene.clear();
} else {
scene.destroy();
delete core.scenes[scene.id];
// delete core.scenes[scene.id];
}
}
}
Expand Down Expand Up @@ -30843,7 +30844,7 @@ class CameraControl extends Component {
}
}

document.addEventListener("keyDown", function (e) {
document.addEventListener("keydown", self._specialKeyDownListener=function (e) {
if (!self._active) {
return;
}
Expand All @@ -30855,7 +30856,7 @@ class CameraControl extends Component {
}
}, true);

document.addEventListener("keyup", function (e) {
document.addEventListener("keyup", self._keyUpListener=function (e) {
if (!self._active) {
return;
}
Expand Down Expand Up @@ -30939,7 +30940,7 @@ class CameraControl extends Component {
yDelta = 0;
});

document.addEventListener("mouseup", function (e) {
document.addEventListener("mouseup", self._mouseUpListener=function (e) {
if (!self._active) {
return;
}
Expand Down Expand Up @@ -31678,7 +31679,7 @@ class CameraControl extends Component {
up: new Float32Array(3)
};

document.addEventListener("keydown", function (e) {
document.addEventListener("keydown", self._cameraAxisKeyDownListener=function (e) {

if (!self._active) {
return;
Expand Down Expand Up @@ -31817,6 +31818,10 @@ class CameraControl extends Component {

destroy() {
this.active = false;
document.removeEventListener("keydown",this._specialKeyDownListener,true);
document.removeEventListener("keyup",this._keyUpListener);
document.removeEventListener("keydown",this._cameraAxisKeyDownListener);
document.removeEventListener("mouseup", this._mouseUpListener);
super.destroy();
}
}
Expand Down
39 changes: 22 additions & 17 deletions build/xeogl.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* WebGL-based 3D visualization library
* http://xeogl.org/
*
* Built on 2020-03-06
* Built on 2020-03-26
*
* MIT License
* Copyright 2020, Lindsay Kay
Expand Down Expand Up @@ -6212,6 +6212,12 @@ class Component {

this.scene._removeComponent(this);

/**
* Fired when this Component is destroyed.
* @event destroyed
*/
this.fire("destroyed", this.destroyed = true);

// Memory leak avoidance
this._attached = {};
this._attachments = null;
Expand All @@ -6223,11 +6229,6 @@ class Component {
this._adoptees = null;
this._updateScheduled = false;

/**
* Fired when this Component is destroyed.
* @event destroyed
*/
this.fire("destroyed", this.destroyed = true);
}
}

Expand Down Expand Up @@ -21644,26 +21645,26 @@ class Input extends Component {
}

destroy() {
super.destroy();
// Prevent memory leak when destroying canvas/WebGL context
document.removeEventListener("keydown", this._keyDownListener);
document.removeEventListener("keydown", this._keyDownListener, true);
document.removeEventListener("keyup", this._keyUpListener);
this._element.removeEventListener("mouseenter", this._mouseEnterListener);
this._element.removeEventListener("mouseleave", this._mouseLeaveListener);
this._element.removeEventListener("mousedown", this._mouseDownListener);
document.removeEventListener("mouseup", this._mouseDownListener);
document.removeEventListener("mouseup", this._mouseUpListener, true);
document.removeEventListener("dblclick", this._dblClickListener);
this._element.removeEventListener("mousemove", this._mouseMoveListener);
this._element.removeEventListener("wheel", this._mouseWheelListener);
if (window.OrientationChangeEvent) {
window.removeEventListener('orientationchange', this._orientationchangedListener);
window.removeEventListener('orientationchange', this._orientationchangedListener, false);
}
if (window.DeviceMotionEvent) {
window.removeEventListener('devicemotion', this._deviceMotionListener);
window.removeEventListener('devicemotion', this._deviceMotionListener, false);
}
if (window.DeviceOrientationEvent) {
window.addEventListener("deviceorientation", this._deviceOrientListener);
window.removeEventListener("deviceorientation", this._deviceOrientListener, false);
}
super.destroy();
}
}

Expand Down Expand Up @@ -28016,7 +28017,7 @@ const core = {
scene.clear();
} else {
scene.destroy();
delete core.scenes[scene.id];
// delete core.scenes[scene.id];
}
}
}
Expand Down Expand Up @@ -30837,7 +30838,7 @@ class CameraControl extends Component {
}
}

document.addEventListener("keyDown", function (e) {
document.addEventListener("keydown", self._specialKeyDownListener=function (e) {
if (!self._active) {
return;
}
Expand All @@ -30849,7 +30850,7 @@ class CameraControl extends Component {
}
}, true);

document.addEventListener("keyup", function (e) {
document.addEventListener("keyup", self._keyUpListener=function (e) {
if (!self._active) {
return;
}
Expand Down Expand Up @@ -30933,7 +30934,7 @@ class CameraControl extends Component {
yDelta = 0;
});

document.addEventListener("mouseup", function (e) {
document.addEventListener("mouseup", self._mouseUpListener=function (e) {
if (!self._active) {
return;
}
Expand Down Expand Up @@ -31672,7 +31673,7 @@ class CameraControl extends Component {
up: new Float32Array(3)
};

document.addEventListener("keydown", function (e) {
document.addEventListener("keydown", self._cameraAxisKeyDownListener=function (e) {

if (!self._active) {
return;
Expand Down Expand Up @@ -31811,6 +31812,10 @@ class CameraControl extends Component {

destroy() {
this.active = false;
document.removeEventListener("keydown",this._specialKeyDownListener,true);
document.removeEventListener("keyup",this._keyUpListener);
document.removeEventListener("keydown",this._cameraAxisKeyDownListener);
document.removeEventListener("mouseup", this._mouseUpListener);
super.destroy();
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,12 @@ class Component {

this.scene._removeComponent(this);

/**
* Fired when this Component is destroyed.
* @event destroyed
*/
this.fire("destroyed", this.destroyed = true);

// Memory leak avoidance
this._attached = {};
this._attachments = null;
Expand All @@ -1067,11 +1073,6 @@ class Component {
this._adoptees = null;
this._updateScheduled = false;

/**
* Fired when this Component is destroyed.
* @event destroyed
*/
this.fire("destroyed", this.destroyed = true);
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/controls/cameraControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ class CameraControl extends Component {
}
}

document.addEventListener("keyDown", function (e) {
document.addEventListener("keydown", self._specialKeyDownListener=function (e) {
if (!self._active) {
return;
}
Expand All @@ -917,7 +917,7 @@ class CameraControl extends Component {
}
}, true);

document.addEventListener("keyup", function (e) {
document.addEventListener("keyup", self._keyUpListener=function (e) {
if (!self._active) {
return;
}
Expand Down Expand Up @@ -1003,7 +1003,7 @@ class CameraControl extends Component {
yDelta = 0;
});

document.addEventListener("mouseup", function (e) {
document.addEventListener("mouseup", self._mouseUpListener=function (e) {
if (!self._active) {
return;
}
Expand Down Expand Up @@ -1748,7 +1748,7 @@ class CameraControl extends Component {
up: new Float32Array(3)
};

document.addEventListener("keydown", function (e) {
document.addEventListener("keydown", self._cameraAxisKeyDownListener=function (e) {

if (!self._active) {
return;
Expand Down Expand Up @@ -1887,6 +1887,10 @@ class CameraControl extends Component {

destroy() {
this.active = false;
document.removeEventListener("keydown",this._specialKeyDownListener,true);
document.removeEventListener("keyup",this._keyUpListener);
document.removeEventListener("keydown",this._cameraAxisKeyDownListener);
document.removeEventListener("mouseup", this._mouseUpListener);
super.destroy();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const core = {
scene.clear();
} else {
scene.destroy();
delete core.scenes[scene.id];
// delete core.scenes[scene.id];
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2210,26 +2210,26 @@ class Input extends Component {
}

destroy() {
super.destroy();
// Prevent memory leak when destroying canvas/WebGL context
document.removeEventListener("keydown", this._keyDownListener);
document.removeEventListener("keydown", this._keyDownListener, true);
document.removeEventListener("keyup", this._keyUpListener);
this._element.removeEventListener("mouseenter", this._mouseEnterListener);
this._element.removeEventListener("mouseleave", this._mouseLeaveListener);
this._element.removeEventListener("mousedown", this._mouseDownListener);
document.removeEventListener("mouseup", this._mouseDownListener);
document.removeEventListener("mouseup", this._mouseUpListener, true);
document.removeEventListener("dblclick", this._dblClickListener);
this._element.removeEventListener("mousemove", this._mouseMoveListener);
this._element.removeEventListener("wheel", this._mouseWheelListener);
if (window.OrientationChangeEvent) {
window.removeEventListener('orientationchange', this._orientationchangedListener);
window.removeEventListener('orientationchange', this._orientationchangedListener, false);
}
if (window.DeviceMotionEvent) {
window.removeEventListener('devicemotion', this._deviceMotionListener);
window.removeEventListener('devicemotion', this._deviceMotionListener, false);
}
if (window.DeviceOrientationEvent) {
window.addEventListener("deviceorientation", this._deviceOrientListener);
window.removeEventListener("deviceorientation", this._deviceOrientListener, false);
}
super.destroy();
}
}

Expand Down

0 comments on commit c062a44

Please sign in to comment.