소스 검색

Properly dispose of background material (#22338)

WestLangley 3 년 전
부모
커밋
07ec316325
1개의 변경된 파일13개의 추가작업 그리고 8개의 파일을 삭제
  1. 13 8
      src/extras/PMREMGenerator.js

+ 13 - 8
src/extras/PMREMGenerator.js

@@ -54,13 +54,6 @@ const ENCODINGS = {
 	[ GammaEncoding ]: 6
 };
 
-const backgroundMaterial = new MeshBasicMaterial( {
-	side: BackSide,
-	depthWrite: false,
-	depthTest: false,
-} );
-const backgroundBox = new Mesh( new BoxGeometry(), backgroundMaterial );
-
 const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
 const { _lodPlanes, _sizeLods, _sigmas } = /*@__PURE__*/ _createPlanes();
 const _clearColor = /*@__PURE__*/ new Color();
@@ -279,8 +272,18 @@ class PMREMGenerator {
 		renderer.outputEncoding = LinearEncoding;
 		renderer.autoClear = false;
 
+		const backgroundMaterial = new MeshBasicMaterial( {
+			name: 'PMREM.Background',
+			side: BackSide,
+			depthWrite: false,
+			depthTest: false,
+		} );
+
+		const backgroundBox = new Mesh( new BoxGeometry(), backgroundMaterial );
+
 		let useSolidColor = false;
 		const background = scene.background;
+
 		if ( background ) {
 
 			if ( background.isColor ) {
@@ -298,7 +301,6 @@ class PMREMGenerator {
 
 		}
 
-
 		for ( let i = 0; i < 6; i ++ ) {
 
 			const col = i % 3;
@@ -333,6 +335,9 @@ class PMREMGenerator {
 
 		}
 
+		backgroundBox.geometry.dispose();
+		backgroundBox.material.dispose();
+
 		renderer.toneMapping = toneMapping;
 		renderer.outputEncoding = outputEncoding;
 		renderer.autoClear = originalAutoClear;