Skip to content

Commit 1686350

Browse files
authored
Sampler: Fix dispose. (#31751)
1 parent bcbf031 commit 1686350

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/renderers/common/Sampler.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ class Sampler extends Binding {
1818

1919
super( name );
2020

21-
/**
22-
* This function is called when the texture is disposed.
23-
* @type {function}
24-
* @private
25-
*/
26-
this._onDisposeTexture = () => {
27-
28-
this.texture = null;
29-
30-
};
31-
3221
/**
3322
* The texture the sampler is referring to.
3423
*
@@ -71,9 +60,17 @@ class Sampler extends Binding {
7160

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

63+
const onDispose = () => {
64+
65+
this._texture = null;
66+
this.generation = null;
67+
this.version = 0;
68+
69+
};
70+
7471
if ( this._texture ) {
7572

76-
this._texture.removeEventListener( 'dispose', this._onDisposeTexture );
73+
this._texture.removeEventListener( 'dispose', onDispose );
7774

7875
}
7976

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

8582
if ( this._texture ) {
8683

87-
this._texture.addEventListener( 'dispose', this._onDisposeTexture );
84+
this._texture.addEventListener( 'dispose', onDispose );
8885

8986
}
9087

@@ -122,6 +119,21 @@ class Sampler extends Binding {
122119

123120
}
124121

122+
123+
clone() {
124+
125+
const clonedSampler = super.clone();
126+
127+
// fix dispose handler for cloned instances
128+
// TODO: Find better solution, see #31747
129+
130+
clonedSampler._texture = null;
131+
clonedSampler.texture = this.texture;
132+
133+
return clonedSampler;
134+
135+
}
136+
125137
}
126138

127139
export default Sampler;

0 commit comments

Comments
 (0)