Skip to content

Commit ec39d34

Browse files
mvaligurskyMartin Valigursky
andauthored
Increase quad buffer size for ministats to allow more stats to render (playcanvas#8259)
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent ed4fa57 commit ec39d34

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/extras/mini-stats/render2d.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SEMANTIC_TEXCOORD0,
1010
TYPE_FLOAT32
1111
} from '../../platform/graphics/constants.js';
12+
import { Debug } from '../../core/debug.js';
1213
import { DepthState } from '../../platform/graphics/depth-state.js';
1314
import { BlendState } from '../../platform/graphics/blend-state.js';
1415
import { GraphNode } from '../../scene/graph-node.js';
@@ -150,7 +151,7 @@ const fragmentShaderWGSL = /* wgsl */ `
150151

151152
// render 2d textured quads
152153
class Render2d {
153-
constructor(device, maxQuads = 512) {
154+
constructor(device, maxQuads = 2048) {
154155
const format = new VertexFormat(device, [
155156
{ semantic: SEMANTIC_POSITION, components: 3, type: TYPE_FLOAT32 },
156157
{ semantic: SEMANTIC_TEXCOORD0, components: 4, type: TYPE_FLOAT32 }
@@ -168,6 +169,7 @@ class Render2d {
168169
}
169170

170171
this.device = device;
172+
this.maxQuads = maxQuads;
171173
this.buffer = new VertexBuffer(device, format, maxQuads * 4, {
172174
usage: BUFFER_STREAM
173175
});
@@ -218,6 +220,12 @@ class Render2d {
218220
}
219221

220222
quad(x, y, w, h, u, v, uw, uh, texture, wordFlag = 0) {
223+
// bounds check to prevent buffer overflow
224+
if (this.quads >= this.maxQuads) {
225+
Debug.warnOnce('MiniStats: maximum number of quads exceeded, some elements may not render.');
226+
return;
227+
}
228+
221229
const rw = this.targetSize.width;
222230
const rh = this.targetSize.height;
223231
const x0 = x / rw;

0 commit comments

Comments
 (0)