Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix game crash when a shadow buffer limit is exceeded #1101

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/platform/w3dengine/client/shadow/w3dbuffermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ W3DBufferManager::W3DVertexBufferSlot *W3DBufferManager::Get_Slot(VBM_FVF_TYPES
int size_index = (size / 32) - 1;

captainslog_dbgassert(size_index < MAX_IB_SIZES && size, "Allocating too large vertex buffer slot");
// #BUGFIX Protect against indexing slots beyond the max size.
// This will happen when a mesh is too complex to draw shadows with.
if (size_index >= MAX_VB_SIZES) {
return nullptr;
}

W3DVertexBufferSlot *vb_slot = m_W3DVertexBufferSlots[fvf_type][size_index];

Expand Down Expand Up @@ -291,6 +296,11 @@ void W3DBufferManager::Release_Slot(W3DVertexBufferSlot *vb_slot)
W3DBufferManager::W3DVertexBufferSlot *W3DBufferManager::Allocate_Slot_Storage(VBM_FVF_TYPES fvf_type, int size)
{
captainslog_dbgassert(m_numEmptyVertexSlotsAllocated < MAX_NUMBER_SLOTS, "Nore more VB Slots");
// #BUGFIX Protect against allocating slot storage beyond the max size.
// This will happen when there are too many meshes in the scene to draw shadows with.
if (m_numEmptyVertexSlotsAllocated >= MAX_NUMBER_SLOTS) {
return nullptr;
}

for (W3DVertexBuffer *vb = m_W3DVertexBuffers[fvf_type]; vb != nullptr; vb = vb->m_nextVB) {

Expand Down Expand Up @@ -365,6 +375,11 @@ W3DBufferManager::W3DIndexBufferSlot *W3DBufferManager::Get_Slot(int size)
int size_index = (size / 32) - 1;

captainslog_dbgassert(size_index < MAX_IB_SIZES && size, "Allocating too large index buffer slot");
// #BUGFIX Protect against indexing slots beyond the max size.
// This will happen when a mesh is too complex to draw shadows with.
if (size_index >= MAX_IB_SIZES) {
return nullptr;
}

W3DIndexBufferSlot *ib_slot = m_W3DIndexBufferSlots[size_index];

Expand Down Expand Up @@ -396,6 +411,11 @@ void W3DBufferManager::Release_Slot(W3DIndexBufferSlot *ib_slot)
W3DBufferManager::W3DIndexBufferSlot *W3DBufferManager::Allocate_Slot_Storage(int size)
{
captainslog_dbgassert(m_numEmptyIndexSlotsAllocated < MAX_NUMBER_SLOTS, "Nore more IB Slots");
// #BUGFIX Protect against allocating slot storage beyond the max size.
// This will happen when there are too many meshes in the scene to draw shadows with.
if (m_numEmptyIndexSlotsAllocated >= MAX_NUMBER_SLOTS) {
return nullptr;
}

for (W3DIndexBuffer *ib = m_W3DIndexBuffers; ib != nullptr; ib = ib->m_nextIB) {

Expand Down
Loading