Skip to content

Commit ece5c89

Browse files
committed
Prevent Stats from instantiating unless explicitly requested
1 parent a291db2 commit ece5c89

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/reaction-diffusion.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,15 @@ export class ReactionDiffusion {
4444
}, 100);
4545
}
4646

47-
// Add Stats module
48-
this.stats = new Stats();
49-
this.container.appendChild(this.stats.dom);
50-
51-
let showDebug = this.container.getAttribute("show-debug");
52-
if (showDebug != "true") this.stats.dom.style.display = "none";
47+
if (this.container.getAttribute("show-debug") == "true") {
48+
// Add Stats module
49+
this.stats = new Stats();
50+
this.container.appendChild(this.stats.dom);
51+
}
5352

5453
// Set up clock for timing
5554
this.clock = new THREE.Clock();
5655

57-
58-
59-
6056
// Call last
6157
this.RenderLoop();
6258
}
@@ -65,15 +61,19 @@ export class ReactionDiffusion {
6561

6662
this.rdView.Render(this.clock);
6763

68-
this.stats.update();
64+
if (this.stats) this.stats.update();
6965

7066
// TODO: Add info block https://threejs.org/docs/#api/en/renderers/WebGLRenderer.info
7167

7268
requestAnimationFrame( this.RenderLoop.bind(this) );
7369
}
7470

7571
ToggleDebug() {
76-
this.stats.dom.style.display = this.stats.dom.style.display == "none" ? "block" : "none";
72+
if (!this.stats) {
73+
this.stats = new Stats();
74+
this.container.appendChild(this.stats.dom);
75+
}
76+
this.stats.dom.style.display = this.stats.dom.style.display == "none" ? "initial" : "none";
7777
}
7878

7979
// Gives a dictionary holding the optional attributes a user might add

0 commit comments

Comments
 (0)