Skip to content

Commit a9b8ea2

Browse files
authored
Merge pull request #753 from Arthur031221/fix/textureeffect-clear-texture-null
Fix TextureEffect crash when clearing an existing texture
2 parents 15d800a + 09308af commit a9b8ea2

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎src/effects/TextureEffect.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ export class TextureEffect extends Effect {
6060
if(prevTexture !== value) {
6161

6262
uniforms.get("map").value = value;
63-
uniforms.get("uvTransform").value = value.matrix;
6463
defines.delete("TEXTURE_PRECISION_HIGH");
6564

6665
if(value !== null) {
6766

67+
uniforms.get("uvTransform").value = value.matrix;
68+
6869
if(value.matrixAutoUpdate) {
6970

7071
defines.set("UV_TRANSFORM", "1");
@@ -89,6 +90,12 @@ export class TextureEffect extends Effect {
8990

9091
}
9192

93+
} else {
94+
95+
uniforms.get("uvTransform").value = null;
96+
defines.delete("UV_TRANSFORM");
97+
this.setVertexShader(null);
98+
9299
}
93100

94101
}

‎test/effects/TextureEffect.js‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from "ava";
2-
import { TextureEffect } from "postprocessing";
2+
import { Texture } from "three";
3+
import { EffectPass, TextureEffect } from "postprocessing";
34

45
test("can be created and destroyed", t => {
56

@@ -16,3 +17,28 @@ test("can be updated", t => {
1617
t.notThrows(() => effect.update());
1718

1819
});
20+
21+
test("can clear an existing texture", t => {
22+
23+
const effect = new TextureEffect({ texture: new Texture() });
24+
t.notThrows(() => { effect.texture = null; });
25+
t.is(effect.texture, null);
26+
27+
});
28+
29+
test("recompiles its host pass after clearing an existing texture", t => {
30+
31+
const texture = new Texture();
32+
texture.matrixAutoUpdate = true;
33+
34+
const effect = new TextureEffect({ texture });
35+
const pass = new EffectPass(null, effect);
36+
pass.initialize(null, false, undefined);
37+
38+
t.true(pass.fullscreenMaterial.vertexShader.includes("UvTransform"));
39+
40+
t.notThrows(() => { effect.texture = null; });
41+
42+
t.false(pass.fullscreenMaterial.vertexShader.includes("UvTransform"));
43+
44+
});

0 commit comments

Comments
 (0)