99 SEMANTIC_TEXCOORD0 ,
1010 TYPE_FLOAT32
1111} from '../../platform/graphics/constants.js' ;
12+ import { Debug } from '../../core/debug.js' ;
1213import { DepthState } from '../../platform/graphics/depth-state.js' ;
1314import { BlendState } from '../../platform/graphics/blend-state.js' ;
1415import { GraphNode } from '../../scene/graph-node.js' ;
@@ -150,7 +151,7 @@ const fragmentShaderWGSL = /* wgsl */ `
150151
151152// render 2d textured quads
152153class 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