Skip to content

Commit 53211f6

Browse files
committed
merged hotfix 2.9.1 into 2.10.0 release
2 parents bf19a69 + eec3e43 commit 53211f6

File tree

13 files changed

+205
-6
lines changed

13 files changed

+205
-6
lines changed

CHANGELOG.md

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

33
## v2.10.0
4-
*20 apr 2023*
4+
*24 apr 2023*
55

66
- Integrated `Vite` to replace `rollup` bundler and integrated `Vitest` for unit testing
77
- Implemented word wrapping support on zero-width breaking spaces (#450) (docs: [Word Wrap in Non-Latin Based Languages](https://lightningjs.io/docs/#/lightning-core-reference/RenderEngine/Textures/Text?id=word-wrap-in-non-latin-based-languages) )
@@ -13,6 +13,12 @@
1313
- Fixed TypeScript error with getByRef() when using generic type param as Ref value (#444)
1414
- Implemented default loose type configs for TypeScript.
1515

16+
## v2.9.1
17+
18+
*21 apr 2023*
19+
20+
- 🔥 Hotfix for memory leak when `pauseRafLoopOnIdle` is enabled (introduced in v2.7.0)
21+
- Implemented additional cleanup of Lightning code that gets stuck on the heap after calling `destroy`
1622

1723
## v2.9.0
1824
*16 feb 2023*

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>

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) {

src/renderer/webgl/WebGLShaderProgram.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default class WebGLShaderProgram {
2828
this.fragmentShaderSource = fragmentShaderSource;
2929

3030
this._program = null;
31+
this.gl = null;
3132

3233
this._uniformLocations = new Map();
3334
this._attributeLocations = new Map();
@@ -109,8 +110,24 @@ export default class WebGLShaderProgram {
109110
destroy() {
110111
if (this._program) {
111112
this.gl.deleteProgram(this._program);
112-
this._program = null;
113113
}
114+
115+
this._attributeLocations = null;
116+
this._currentUniformValues = null;
117+
this.fragmentShaderSource = null;
118+
this._program = null;
119+
this.gl = null;
120+
this._uniformLocations = null;
121+
this.vertexShaderSource = null;
122+
123+
delete this.vertexShaderSource;
124+
delete this._program;
125+
delete this._currentUniformValues;
126+
delete this.fragmentShaderSource;
127+
delete this.gl;
128+
delete this._uniformLocations;
129+
delete this._attributeLocations;
130+
114131
}
115132

116133
get glProgram() {

src/tree/Stage.mjs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default class Stage extends EventEmitter {
140140

141141
try {
142142
return !!window.WebGLRenderingContext;
143-
} catch(e) {
143+
} catch (e) {
144144
return false;
145145
}
146146
}
@@ -188,7 +188,7 @@ export default class Stage extends EventEmitter {
188188
opt('memoryPressure', 24e6);
189189
opt('bufferMemory', 2e6);
190190
opt('textRenderIssueMargin', 0);
191-
opt('fontSharp',{precision:0.6666666667, fontSize: 24})
191+
opt('fontSharp', { precision: 0.6666666667, fontSize: 24 })
192192
opt('clearColor', [0, 0, 0, 0]);
193193
opt('defaultFontFace', 'sans-serif');
194194
opt('fixedDt', 0);
@@ -238,6 +238,32 @@ export default class Stage extends EventEmitter {
238238
this.ctx.destroy();
239239
this.textureManager.destroy();
240240
this._renderer.destroy();
241+
242+
// clear last rendered frame
243+
if (this.gl) {
244+
this.gl.clearColor(0.0, 0.0, 0.0, 0.0);
245+
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
246+
} else if (this.c2d) {
247+
this.c2d.clearRect(
248+
0, 0, this.c2d.canvas.width, this.c2d.canvas.height
249+
);
250+
}
251+
252+
this.gl = null;
253+
this.c2d = null;
254+
this.ctx = null;
255+
this._options = null;
256+
this.platform = null;
257+
this.textureManager = null;
258+
this._renderer = null;
259+
260+
delete this.gl;
261+
delete this.c2d;
262+
delete this.ctx;
263+
delete this._options;
264+
delete this.platform;
265+
delete this.textureManager;
266+
delete this._renderer;
241267
}
242268

243269
stop() {
@@ -511,10 +537,10 @@ export default class Stage extends EventEmitter {
511537
}
512538
}
513539

514-
getChildrenByPosition(x, y){
540+
getChildrenByPosition(x, y) {
515541
const children = [];
516542
this.root.core.update();
517-
this.root.core.collectAtCoord(x,y,children);
543+
this.root.core.collectAtCoord(x, y, children);
518544

519545
return children;
520546
}

src/tree/TextureThrottler.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export default class TextureThrottler {
3636
destroy() {
3737
this._sources = [];
3838
this._data = [];
39+
this.stage = null;
40+
41+
delete this._sources;
42+
delete this._data;
43+
delete this.stage;
3944
}
4045

4146
processSome() {

src/tree/core/CoreContext.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ export default class CoreContext {
4949
destroy() {
5050
this._renderTexturePool.forEach(texture => this._freeRenderTexture(texture));
5151
this._usedMemory = 0;
52+
53+
this.stage = null;
54+
this.root = null;
55+
56+
this.renderState = null;
57+
this.renderExec = null;
58+
this._renderTexturePool = null;
59+
this._zSorts = null;
60+
61+
delete this.stage;
62+
delete this.root;
63+
delete this.renderState;
64+
delete this.renderExec;
65+
delete this._renderTexturePool;
66+
delete this._zSorts;
5267
}
5368

5469
hasRenderUpdates() {

src/tree/core/CoreRenderExecutor.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ export default class CoreRenderExecutor {
2929
}
3030

3131
destroy() {
32+
this.ctx = null;
33+
this.renderState = null;
34+
this.gl = null;
35+
36+
delete this.ctx;
37+
delete this.renderState;
38+
delete this.gl;
3239
}
3340

3441
_reset() {

0 commit comments

Comments
 (0)