Browse Source

Examples: Call `ImageBitmap.close()` in `webgl_loader_imagebitmap`. (#30977)

Michael Herzog 8 months ago
parent
commit
688fdaf9cf
1 changed files with 9 additions and 3 deletions
  1. 9 3
      examples/webgl_loader_imagebitmap.html

+ 9 - 3
examples/webgl_loader_imagebitmap.html

@@ -38,10 +38,9 @@
 						texture.colorSpace = THREE.SRGBColorSpace;
 						const material = new THREE.MeshBasicMaterial( { map: texture } );
 
-						/* ImageBitmap should be disposed when done with it
-						   Can't be done until it's actually uploaded to WebGLTexture */
+						// ImageBitmap should be disposed when done with it.
 
-						// imageBitmap.close();
+						texture.onUpdate = disposeImageBitmap;
 
 						addCube( material );
 
@@ -148,6 +147,13 @@
 
 			}
 
+			function disposeImageBitmap( texture ) {
+
+				texture.source.data.close();
+				texture.onUpdate = null; // make sure this callback is executed only once per texture
+
+			}
+
 		</script>
 
 	</body>

粤ICP备19079148号