Skip to content
Merged
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
61 changes: 10 additions & 51 deletions src/renderers/common/Sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,14 @@ class Sampler extends Binding {
* @private
* @type {?Texture}
*/
this._texture = null;

/**
* An event listener which is added to {@link texture}'s dispose event.
*
* @private
* @type {Function}
*/
this._onTextureDispose = () => {

this.generation = null;
this.version = - 1;

};

// Assignment to the texture via a setter must occur after "_onTextureDispose" is initialized.
this.texture = texture;
this._texture = texture;

/**
* The binding's version.
*
* @type {number}
*/
this.version = texture ? texture.version : - 1;
this.version = - 1;

/**
* The binding's generation which is an additional version
Expand Down Expand Up @@ -86,22 +70,9 @@ class Sampler extends Binding {

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

if ( this._texture ) {

this._texture.removeEventListener( 'dispose', this._onTextureDispose );

}

this._texture = value;

this.generation = null;
this.version = - 1;

if ( this._texture ) {

this._texture.addEventListener( 'dispose', this._onTextureDispose );

}
this.reset();

}

Expand Down Expand Up @@ -137,26 +108,14 @@ class Sampler extends Binding {

}

/**
* Resets the version and generation. This is used when the texture
* the binding is pointing to is disposed or exchanged.
*/
reset() {

clone() {

const clonedSampler = super.clone();

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

clonedSampler._texture = null;

clonedSampler._onTextureDispose = () => {

clonedSampler.generation = null;
clonedSampler.version = - 1;

};

clonedSampler.texture = this.texture;

return clonedSampler;
this.generation = null;
this.version = - 1;

}

Expand Down
12 changes: 12 additions & 0 deletions src/renderers/common/Textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,18 @@ class Textures extends DataMap {
bindingsData.groups = undefined;
bindingsData.versions = undefined;

// go through all bindings and if one points to the destroyed texture, trigger dispose as well

for ( const binding of bindGroup.bindings ) {

if ( binding.isSampler && binding.texture === texture ) {

binding.reset();

}

}

}

}
Expand Down
Loading