@@ -210,8 +210,8 @@ Bool W3DBufferManager::ReAcquireResources(void)
210
210
}
211
211
212
212
/* *Searches through previously allocated vertex buffer slots and returns a matching type. If none found,
213
- creates a new slot and adds it to the pool. Returns an integer slotId used to reference the VB.
214
- Returns -1 in case of failure.
213
+ creates a new slot and adds it to the pool. Returns a pointer to the VB slot .
214
+ Returns NULL in case of failure.
215
215
*/
216
216
W3DBufferManager::W3DVertexBufferSlot *W3DBufferManager::getSlot (VBM_FVF_TYPES fvfType, Int size)
217
217
{
@@ -222,9 +222,14 @@ W3DBufferManager::W3DVertexBufferSlot *W3DBufferManager::getSlot(VBM_FVF_TYPES f
222
222
size = (size + (MIN_SLOT_SIZE-1 )) & (~(MIN_SLOT_SIZE-1 ));
223
223
Int sizeIndex = (size >> MIN_SLOT_SIZE_SHIFT)-1 ;
224
224
225
- DEBUG_ASSERTCRASH (sizeIndex < MAX_VB_SIZES && size, (" Allocating too large vertex buffer slot" ));
225
+ DEBUG_ASSERTCRASH (sizeIndex < MAX_VB_SIZES && size > 0 , (" Allocating too large vertex buffer slot" ));
226
+ // TheSuperHackers @bugfix xezon 18/05/2025 Protect against indexing slots beyond the max size.
227
+ // This will happen when a mesh is too complex to draw shadows with.
228
+ if (sizeIndex >= MAX_VB_SIZES || size <= 0 ) {
229
+ return NULL ;
230
+ }
226
231
227
- if ((vbSlot=m_W3DVertexBufferSlots[fvfType][sizeIndex]) != 0 )
232
+ if ((vbSlot=m_W3DVertexBufferSlots[fvfType][sizeIndex]) != NULL )
228
233
{ // found a previously allocated slot matching required size
229
234
m_W3DVertexBufferSlots[fvfType][sizeIndex]=vbSlot->m_nextSameSize ;
230
235
if (vbSlot->m_nextSameSize )
@@ -260,31 +265,32 @@ W3DBufferManager::W3DVertexBufferSlot * W3DBufferManager::allocateSlotStorage(VB
260
265
W3DVertexBufferSlot *vbSlot;
261
266
// Int sizeIndex = (size >> MIN_SLOT_SIZE_SHIFT)-1;
262
267
263
- DEBUG_ASSERTCRASH (m_numEmptySlotsAllocated < MAX_NUMBER_SLOTS, (" Nore more VB Slots" ));
268
+ DEBUG_ASSERTCRASH (m_numEmptySlotsAllocated < MAX_NUMBER_SLOTS, (" No more VB Slots" ));
269
+ // TheSuperHackers @bugfix xezon 18/05/2025 Protect against allocating slot storage beyond the max size.
270
+ // This will happen when there are too many meshes in the scene to draw shadows with.
271
+ if (m_numEmptySlotsAllocated >= MAX_NUMBER_SLOTS) {
272
+ return NULL ;
273
+ }
264
274
265
275
pVB=m_W3DVertexBuffers[fvfType];
266
276
while (pVB)
267
277
{
268
278
if ((pVB->m_size - pVB->m_startFreeIndex ) >= size)
269
279
{ // found enough free space in this vertex buffer
270
-
271
- if (m_numEmptySlotsAllocated < MAX_NUMBER_SLOTS)
272
- { // we're allowing more slots to be allocated.
273
- vbSlot=&m_W3DVertexBufferEmptySlots[m_numEmptySlotsAllocated];
274
- vbSlot->m_size =size;
275
- vbSlot->m_start =pVB->m_startFreeIndex ;
276
- vbSlot->m_VB =pVB;
277
- // Link to VB list of slots
278
- vbSlot->m_nextSameVB =pVB->m_usedSlots ;
279
- vbSlot->m_prevSameVB =NULL ; // this will be the new head
280
- if (pVB->m_usedSlots )
281
- pVB->m_usedSlots ->m_prevSameVB =vbSlot;
282
- vbSlot->m_prevSameSize =vbSlot->m_nextSameSize =NULL ;
283
- pVB->m_usedSlots =vbSlot;
284
- pVB->m_startFreeIndex += size;
285
- m_numEmptySlotsAllocated++;
286
- return vbSlot;
287
- }
280
+ vbSlot=&m_W3DVertexBufferEmptySlots[m_numEmptySlotsAllocated];
281
+ vbSlot->m_size =size;
282
+ vbSlot->m_start =pVB->m_startFreeIndex ;
283
+ vbSlot->m_VB =pVB;
284
+ // Link to VB list of slots
285
+ vbSlot->m_nextSameVB =pVB->m_usedSlots ;
286
+ vbSlot->m_prevSameVB =NULL ; // this will be the new head
287
+ if (pVB->m_usedSlots )
288
+ pVB->m_usedSlots ->m_prevSameVB =vbSlot;
289
+ vbSlot->m_prevSameSize =vbSlot->m_nextSameSize =NULL ;
290
+ pVB->m_usedSlots =vbSlot;
291
+ pVB->m_startFreeIndex += size;
292
+ m_numEmptySlotsAllocated++;
293
+ return vbSlot;
288
294
}
289
295
pVB = pVB->m_nextVB ;
290
296
}
@@ -324,8 +330,8 @@ W3DBufferManager::W3DVertexBufferSlot * W3DBufferManager::allocateSlotStorage(VB
324
330
325
331
// ******************************** Index Buffer code ******************************************************
326
332
/* *Searches through previously allocated index buffer slots and returns a matching type. If none found,
327
- creates a new slot and adds it to the pool. Returns an integer slotId used to reference the VB .
328
- Returns -1 in case of failure.
333
+ creates a new slot and adds it to the pool. Returns a pointer to the IB slot .
334
+ Returns NULL in case of failure.
329
335
*/
330
336
W3DBufferManager::W3DIndexBufferSlot *W3DBufferManager::getSlot (Int size)
331
337
{
@@ -336,9 +342,14 @@ W3DBufferManager::W3DIndexBufferSlot *W3DBufferManager::getSlot(Int size)
336
342
size = (size + (MIN_SLOT_SIZE-1 )) & (~(MIN_SLOT_SIZE-1 ));
337
343
Int sizeIndex = (size >> MIN_SLOT_SIZE_SHIFT)-1 ;
338
344
339
- DEBUG_ASSERTCRASH (sizeIndex < MAX_IB_SIZES && size, (" Allocating too large index buffer slot" ));
345
+ DEBUG_ASSERTCRASH (sizeIndex < MAX_IB_SIZES && size > 0 , (" Allocating too large index buffer slot" ));
346
+ // TheSuperHackers @bugfix xezon 18/05/2025 Protect against indexing slots beyond the max size.
347
+ // This will happen when a mesh is too complex to draw shadows with.
348
+ if (sizeIndex >= MAX_IB_SIZES || size <= 0 ) {
349
+ return NULL ;
350
+ }
340
351
341
- if ((ibSlot=m_W3DIndexBufferSlots[sizeIndex]) != 0 )
352
+ if ((ibSlot=m_W3DIndexBufferSlots[sizeIndex]) != NULL )
342
353
{ // found a previously allocated slot matching required size
343
354
m_W3DIndexBufferSlots[sizeIndex]=ibSlot->m_nextSameSize ;
344
355
if (ibSlot->m_nextSameSize )
@@ -374,31 +385,32 @@ W3DBufferManager::W3DIndexBufferSlot * W3DBufferManager::allocateSlotStorage(Int
374
385
W3DIndexBufferSlot *ibSlot;
375
386
// Int sizeIndex = (size >> MIN_SLOT_SIZE_SHIFT)-1;
376
387
377
- DEBUG_ASSERTCRASH (m_numEmptyIndexSlotsAllocated < MAX_NUMBER_SLOTS, (" Nore more IB Slots" ));
388
+ DEBUG_ASSERTCRASH (m_numEmptyIndexSlotsAllocated < MAX_NUMBER_SLOTS, (" No more IB Slots" ));
389
+ // TheSuperHackers @bugfix xezon 18/05/2025 Protect against allocating slot storage beyond the max size.
390
+ // This will happen when there are too many meshes in the scene to draw shadows with.
391
+ if (m_numEmptyIndexSlotsAllocated >= MAX_NUMBER_SLOTS) {
392
+ return NULL ;
393
+ }
378
394
379
395
pIB=m_W3DIndexBuffers;
380
396
while (pIB)
381
397
{
382
398
if ((pIB->m_size - pIB->m_startFreeIndex ) >= size)
383
399
{ // found enough free space in this index buffer
384
-
385
- if (m_numEmptyIndexSlotsAllocated < MAX_NUMBER_SLOTS)
386
- { // we're allowing more slots to be allocated.
387
- ibSlot=&m_W3DIndexBufferEmptySlots[m_numEmptyIndexSlotsAllocated];
388
- ibSlot->m_size =size;
389
- ibSlot->m_start =pIB->m_startFreeIndex ;
390
- ibSlot->m_IB =pIB;
391
- // Link to IB list of slots
392
- ibSlot->m_nextSameIB =pIB->m_usedSlots ;
393
- ibSlot->m_prevSameIB =NULL ; // this will be the new head
394
- if (pIB->m_usedSlots )
395
- pIB->m_usedSlots ->m_prevSameIB =ibSlot;
396
- ibSlot->m_prevSameSize =ibSlot->m_nextSameSize =NULL ;
397
- pIB->m_usedSlots =ibSlot;
398
- pIB->m_startFreeIndex += size;
399
- m_numEmptyIndexSlotsAllocated++;
400
- return ibSlot;
401
- }
400
+ ibSlot=&m_W3DIndexBufferEmptySlots[m_numEmptyIndexSlotsAllocated];
401
+ ibSlot->m_size =size;
402
+ ibSlot->m_start =pIB->m_startFreeIndex ;
403
+ ibSlot->m_IB =pIB;
404
+ // Link to IB list of slots
405
+ ibSlot->m_nextSameIB =pIB->m_usedSlots ;
406
+ ibSlot->m_prevSameIB =NULL ; // this will be the new head
407
+ if (pIB->m_usedSlots )
408
+ pIB->m_usedSlots ->m_prevSameIB =ibSlot;
409
+ ibSlot->m_prevSameSize =ibSlot->m_nextSameSize =NULL ;
410
+ pIB->m_usedSlots =ibSlot;
411
+ pIB->m_startFreeIndex += size;
412
+ m_numEmptyIndexSlotsAllocated++;
413
+ return ibSlot;
402
414
}
403
415
pIB = pIB->m_nextIB ;
404
416
}
0 commit comments