Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/tree/Element.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ export default class Element {
_unsetActiveFlag() {
if (this.__texture) {
this.__texture.decActiveCount();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guilhermesimoes the decActiveCount is called here? so im not sure this is actually a fix..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the test that I added fails without the current change in Element 🤔 but you're right, let me take a look

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we're dealing with different textures! This leak only occurs when the element is swapping srcs / textures. I've updated the PR which hopefully should make the issue clearer.


if (this.__displayedTexture && this.__displayedTexture !== this.__texture) {
this.__displayedTexture.decActiveCount();
}
}

this.__active = false;
Expand Down
20 changes: 20 additions & 0 deletions tests/textures/test.textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ describe('Textures', function() {

chai.assert(texture.isLoaded(), "Texture must be loaded");
});

it('should recover load [with throttling]', () => {
const element = app.stage.createElement({
Item: {x: 550, texture: {type: TestTexture, async: true}}
Expand Down Expand Up @@ -595,6 +596,25 @@ describe('Textures', function() {

chai.assert(!stage.textureManager.getReusableTextureSource("test1"), "lookup id should be removed");
});

it('should release old source when element becomes inactive after src swap', () => {
const element = app.stage.createElement({
Item: {texture: {type: TestTexture, lookupId: "old"}}
});
app.children = [element];
stage.drawFrame();

const item = app.tag("Item");
const oldTextureSource = item.texture.source;

item.texture = {type: TestTexture, lookupId: "new"};
item.visible = false;
stage.drawFrame();
stage.gc();

chai.assert(!oldTextureSource.isUsed(), "Old texture source should no longer be in use");
chai.assert(!stage.textureManager._uploadedTextureSources.includes(oldTextureSource), "Old texture source should be cleaned up by gc");
});
});

describe('previously removed texture source', () => {
Expand Down
Loading