Browse Source

Merge pull request #1250 from sebavan/master

Test Capabilities Canvas Cleanup
David Catuhe 9 năm trước cách đây
mục cha
commit
1a5f29fc19
1 tập tin đã thay đổi với 14 bổ sung1 xóa
  1. 14 1
      src/babylon.engine.ts

+ 14 - 1
src/babylon.engine.ts

@@ -2722,9 +2722,20 @@
             var fb = gl.createFramebuffer();
             gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
             gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
+            
+            var cleanup = function() {
+                gl.deleteProgram(program);
+                gl.disableVertexAttribArray(positionLocation);
+                gl.deleteBuffer(positionBuffer);
+                gl.deleteFramebuffer(fb);
+                gl.deleteTexture(whiteTex);
+                gl.deleteTexture(tex);
+            };
+
             var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
             if (status !== gl.FRAMEBUFFER_COMPLETE) {
                 Tools.Log("GL Support: can **NOT** render to " + format + " texture");
+                cleanup();
                 return false;
             }
             
@@ -2749,10 +2760,12 @@
                 pixel[2] < 248 ||
                 pixel[3] < 254) {
                 BABYLON.Tools.Log("GL Support: Was not able to actually render to " + format + " texture");
+                cleanup();
                 return false;
             }
-            
+
             // Succesfully rendered to "format" texture.
+            cleanup();
             return true;
         }