Jelajahi Sumber

Merge pull request #9670 from Popov72/contextlost-dumpinfo

NME texture blocks: dispose textures when disposing of blocks
sebavan 4 tahun lalu
induk
melakukan
ce795e1f8b

+ 4 - 1
src/Engines/thinEngine.ts

@@ -2249,10 +2249,13 @@ export class ThinEngine {
 
     private _compileRawShader(source: string, type: string): WebGLShader {
         var gl = this._gl;
+
+        while (gl.getError() != gl.NO_ERROR) { }
+
         var shader = gl.createShader(type === "vertex" ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);
 
         if (!shader) {
-            throw new Error(`Something went wrong while creating a gl ${type} shader object. gl error=${gl.getError()}`);
+            throw new Error(`Something went wrong while creating a gl ${type} shader object. gl error=${gl.getError()}, gl isContextLost=${gl.isContextLost()}, _contextWasLost=${this._contextWasLost}`);
         }
 
         gl.shaderSource(shader, source);

+ 5 - 0
src/Materials/Node/Blocks/Dual/currentScreenBlock.ts

@@ -300,6 +300,11 @@ export class CurrentScreenBlock extends NodeMaterialBlock {
             this.texture = Texture.Parse(serializationObject.texture, scene, rootUrl) as Texture;
         }
     }
+
+    public dispose() {
+        super.dispose();
+        this.texture?.dispose();
+    }
 }
 
 _TypeStore.RegisteredTypes["BABYLON.CurrentScreenBlock"] = CurrentScreenBlock;

+ 5 - 0
src/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.ts

@@ -459,6 +459,11 @@ export abstract class ReflectionTextureBaseBlock extends NodeMaterialBlock {
             }
         }
     }
+
+    public dispose() {
+        super.dispose();
+        this.texture?.dispose();
+    }
 }
 
 _TypeStore.RegisteredTypes["BABYLON.ReflectionTextureBaseBlock"] = ReflectionTextureBaseBlock;

+ 5 - 0
src/Materials/Node/Blocks/Dual/textureBlock.ts

@@ -449,6 +449,11 @@ export class TextureBlock extends NodeMaterialBlock {
             this.texture = Texture.Parse(serializationObject.texture, scene, rootUrl) as Texture;
         }
     }
+
+    public dispose() {
+        super.dispose();
+        this.texture?.dispose();
+    }
 }
 
 _TypeStore.RegisteredTypes["BABYLON.TextureBlock"] = TextureBlock;

+ 5 - 0
src/Materials/Node/Blocks/PBR/refractionBlock.ts

@@ -349,6 +349,11 @@ export class RefractionBlock extends NodeMaterialBlock {
         this.linkRefractionWithTransparency = serializationObject.linkRefractionWithTransparency;
         this.invertRefractionY = serializationObject.invertRefractionY;
     }
+
+    public dispose() {
+        super.dispose();
+        this.texture?.dispose();
+    }
 }
 
 _TypeStore.RegisteredTypes["BABYLON.RefractionBlock"] = RefractionBlock;

+ 5 - 0
src/Materials/Node/Blocks/Particle/particleTextureBlock.ts

@@ -218,6 +218,11 @@ export class ParticleTextureBlock extends NodeMaterialBlock {
             this.texture = Texture.Parse(serializationObject.texture, scene, rootUrl) as Texture;
         }
     }
+
+    public dispose() {
+        super.dispose();
+        this.texture?.dispose();
+    }
 }
 
 _TypeStore.RegisteredTypes["BABYLON.ParticleTextureBlock"] = ParticleTextureBlock;