Skip to content

Commit

Permalink
Properly dispose of background material (#22338)
Browse files Browse the repository at this point in the history
  • Loading branch information
WestLangley authored Aug 24, 2021
1 parent 8f04662 commit 07ec316
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/extras/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 ) {
Expand All @@ -298,7 +301,6 @@ class PMREMGenerator {

}


for ( let i = 0; i < 6; i ++ ) {

const col = i % 3;
Expand Down Expand Up @@ -333,6 +335,9 @@ class PMREMGenerator {

}

backgroundBox.geometry.dispose();
backgroundBox.material.dispose();

renderer.toneMapping = toneMapping;
renderer.outputEncoding = outputEncoding;
renderer.autoClear = originalAutoClear;
Expand Down

0 comments on commit 07ec316

Please sign in to comment.