Skip to content
Merged
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
38 changes: 25 additions & 13 deletions src/renderers/common/Sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ class Sampler extends Binding {

super( name );

/**
* This function is called when the texture is disposed.
* @type {function}
* @private
*/
this._onDisposeTexture = () => {
Copy link
Collaborator Author

@Mugen87 Mugen87 Aug 26, 2025

Choose a reason for hiding this comment

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

_onDisposeTexture() is cloned like all other properties. Because EventListener does not let you assign the same listener more than once, only the first dispose works. It has to be inlined in the setter of texture to make it work.


this.texture = null;

};

/**
* The texture the sampler is referring to.
*
Expand Down Expand Up @@ -71,9 +60,17 @@ class Sampler extends Binding {

if ( this._texture === value ) return;

const onDispose = () => {

this._texture = null;
this.generation = null;
this.version = 0;

};

if ( this._texture ) {

this._texture.removeEventListener( 'dispose', this._onDisposeTexture );
this._texture.removeEventListener( 'dispose', onDispose );

}

Expand All @@ -84,7 +81,7 @@ class Sampler extends Binding {

if ( this._texture ) {

this._texture.addEventListener( 'dispose', this._onDisposeTexture );
this._texture.addEventListener( 'dispose', onDispose );

}

Expand Down Expand Up @@ -122,6 +119,21 @@ class Sampler extends Binding {

}


clone() {

const clonedSampler = super.clone();

// fix dispose handler for cloned instances
// TODO: Find better solution, see #31747

clonedSampler._texture = null;
clonedSampler.texture = this.texture;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An explicit call of the texture setter is required so cloned instances have proper dispose event listeners.


return clonedSampler;

}

}

export default Sampler;
Loading