Skip to content

Commit eec3e43

Browse files
committed
Merge branch 'master' into dev
2 parents 27f19ba + a7c77d3 commit eec3e43

15 files changed

+208
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v2.9.1
4+
5+
*21 apr 2023*
6+
7+
- 🔥 Hotfix for memory leak when `pauseRafLoopOnIdle` is enabled (introduced in v2.7.0)
8+
- Implemented additional cleanup of Lightning code that gets stuck on the heap after calling `destroy`
9+
310
## v2.9.0
411
*16 feb 2023*
512

examples/destroy/index.html

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!--
2+
If not stated otherwise in this file or this component's LICENSE file the
3+
following copyright and licenses apply:
4+
5+
Copyright 2020 Metrological
6+
7+
Licensed under the Apache License, Version 2.0 (the License);
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
-->
19+
20+
<!DOCTYPE html>
21+
<html lang="en">
22+
<head>
23+
<meta charset="UTF-8" />
24+
<script src="../../../devtools/lightning-inspect.js"></script>
25+
</head>
26+
<body style="margin: 0; padding: 0">
27+
<script type="module">
28+
import lng from '../../../src/lightning.mjs';
29+
//attachInspector(lng)
30+
31+
let app = null;
32+
let canvas = null;
33+
const loadApp = () => {
34+
class BasicUsageExample extends lng.Application {
35+
static _template() {
36+
return {
37+
Bg: {
38+
src: "../landscape.jpg", scale: 1,
39+
},
40+
Primary: {
41+
Main: {rect: true, renderToTexture: true, w: 900, h: 900, colorLeft: 0x000000FF, colorRight: 0xFF0000FF
42+
},
43+
App: {alpha: 0.5, rect: true, w: 100, h: 100, scale: 1, texture: {type: lng.textures.NoiseTexture, x: 0, y: 0, w: 1000, h: 1000}}
44+
},
45+
Overlay: {}
46+
}
47+
}
48+
49+
_handleLeft() {
50+
this.tag('Primary').setSmooth('x', this.tag('Primary').getSmooth('x') - 100)
51+
}
52+
53+
_handleRight() {
54+
this.tag('Primary').setSmooth('x', this.tag('Primary').getSmooth('x') + 100)
55+
this._setState("Loading");
56+
}
57+
58+
_handleUp() {
59+
this.tag('Primary').setSmooth('y', this.tag('Primary').getSmooth('y') - 100)
60+
}
61+
62+
_handleDown() {
63+
this.tag('Primary').setSmooth('y', this.tag('Primary').getSmooth('y') + 100)
64+
}
65+
66+
}
67+
68+
const options = {
69+
stage: {
70+
w: 900, h: 900, clearColor: 0xFF000000, canvas2d: false, useImageWorker: false,
71+
forceTxCanvasSource: true,
72+
pauseRafLoopOnIdle: true
73+
}, debug: true}
74+
75+
app = new BasicUsageExample(options);
76+
canvas = app.stage.getCanvas()
77+
document.body.appendChild(app.stage.getCanvas());
78+
}
79+
80+
81+
document.addEventListener("keydown", (e) => {
82+
// spacebar
83+
if (e.keyCode === 32) {
84+
if (app) {
85+
app.destroy();
86+
document.body.removeChild(canvas);
87+
canvas = null;
88+
return app = null;
89+
}
90+
91+
loadApp();
92+
}
93+
})
94+
</script>
95+
</body>
96+
</html>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Metrological, Bas van Meurs <[email protected]>",
33
"name": "@lightningjs/core",
4-
"version": "2.9.0",
4+
"version": "2.9.1",
55
"license": "Apache-2.0",
66
"type": "module",
77
"types": "dist/index.d.ts",

src/platforms/browser/ImageWorker.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export default class ImageWorker {
3030
if (this._worker) {
3131
this._worker.terminate();
3232
}
33+
34+
this._items = null;
35+
this._worker = null;
36+
37+
delete this._items;
38+
delete this._worker;
3339
}
3440

3541
_initWorker() {

src/platforms/browser/WebPlatform.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ export default class WebPlatform {
5050
if (this._imageWorker) {
5151
this._imageWorker.destroy();
5252
}
53+
54+
clearInterval(this._loopHandler);
55+
5356
this._removeKeyHandler();
5457
this._removeClickHandler();
5558
this._removeHoverHandler();
5659
this._removeScrollWheelHandler();
5760
this._removeVisibilityChangeHandler();
61+
62+
this.stage = null;
63+
delete this.stage;
5864
}
5965

6066
startLoop() {

src/renderer/c2d/C2dRenderer.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export default class C2dRenderer extends Renderer {
3838

3939
destroy() {
4040
this.tintManager.destroy();
41+
42+
this.tintManager = null;
43+
delete this.tintManager;
4144
}
4245

4346
_createDefaultShader(ctx) {

src/renderer/c2d/C2dTextureTintManager.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export default class C2dTextureTintManager {
2727

2828
destroy() {
2929
this.gc(true);
30+
31+
this.stage = null;
32+
delete this.stage;
3033
}
3134

3235
_addMemoryUsage(delta) {

src/renderer/webgl/WebGLCoreRenderExecutor.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export default class WebGLCoreRenderExecutor extends CoreRenderExecutor {
6464
super.destroy();
6565
this.gl.deleteBuffer(this._attribsBuffer);
6666
this.gl.deleteBuffer(this._quadsBuffer);
67+
68+
this.gl = null;
69+
delete this.gl;
6770
}
6871

6972
_reset() {

src/renderer/webgl/WebGLRenderer.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export default class WebGLRenderer extends Renderer {
4646

4747
destroy() {
4848
this.shaderPrograms.forEach(shaderProgram => shaderProgram.destroy());
49+
50+
this.shaderPrograms = null;
51+
this._compressedTextureExtensions = null;
52+
53+
delete this.shaderPrograms;
54+
delete this._compressedTextureExtensions;
4955
}
5056

5157
_createDefaultShader(ctx) {

0 commit comments

Comments
 (0)