diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp index 72efdf7b6b9..d91927f8f20 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp @@ -1254,19 +1254,24 @@ void W3DVolumetricShadow::RenderMeshVolume(Int meshIndex, Int lightIndex, const W3DBufferManager::W3DVertexBufferSlot *vbSlot=m_shadowVolumeVB[lightIndex][ meshIndex ]; if (!vbSlot) return; + + // Check if buffer is too small - skip rendering if shadow is too complex + if (vbSlot->m_size < numVerts) + return; + if (vbSlot->m_VB->m_DX8VertexBuffer->Get_DX8_Vertex_Buffer() != lastActiveVertexBuffer) { lastActiveVertexBuffer=vbSlot->m_VB->m_DX8VertexBuffer->Get_DX8_Vertex_Buffer(); m_pDev->SetStreamSource(0,lastActiveVertexBuffer, vbSlot->m_VB->m_DX8VertexBuffer->FVF_Info().Get_FVF_Size()); //12 bytes per vertex. } - DEBUG_ASSERTCRASH(vbSlot->m_size >= numVerts,("Overflowing Shadow Vertex Buffer Slot")); - W3DBufferManager::W3DIndexBufferSlot *ibSlot=m_shadowVolumeIB[lightIndex][ meshIndex ]; if (!ibSlot) return; - DEBUG_ASSERTCRASH(ibSlot->m_size >= numIndex,("Overflowing Shadow Index Buffer Slot")); + // Check if buffer is too small - skip rendering if shadow is too complex + if (ibSlot->m_size < numIndex) + return; m_pDev->SetIndices(ibSlot->m_IB->m_DX8IndexBuffer->Get_DX8_Index_Buffer(),vbSlot->m_start); @@ -2794,10 +2799,14 @@ void W3DVolumetricShadow::constructVolumeVB( Vector3 *lightPosObject,Real shadow vbSlot=m_shadowVolumeVB[ volumeIndex ][meshIndex] = TheW3DBufferManager->getSlot(W3DBufferManager::VBM_FVF_XYZ, vertexCount); - DEBUG_ASSERTCRASH(vbSlot != NULL, ("Can't allocate vertex buffer slot for shadow volume")); - if (vbSlot != NULL) + // Check if vertex buffer allocation failed or is too small + if (vbSlot == NULL || vbSlot->m_size < vertexCount) { - DEBUG_ASSERTCRASH(vbSlot->m_size >= vertexCount,("Overflowing Shadow Vertex Buffer Slot")); + // Shadow volume too complex for available buffers - skip rendering instead of crashing + if (vbSlot) + TheW3DBufferManager->releaseSlot(vbSlot); + m_shadowVolumeVB[ volumeIndex ][meshIndex] = NULL; + return; } DEBUG_ASSERTCRASH(m_shadowVolume[ volumeIndex ][meshIndex]->GetNumPolygon() == 0,("Updating Existing Static Shadow Volume")); @@ -2805,21 +2814,16 @@ void W3DVolumetricShadow::constructVolumeVB( Vector3 *lightPosObject,Real shadow DEBUG_ASSERTCRASH(m_shadowVolumeIB[ volumeIndex ][meshIndex] == NULL,("Updating Existing Static Index Buffer Shadow")); ibSlot=m_shadowVolumeIB[ volumeIndex ][meshIndex] = TheW3DBufferManager->getSlot(polygonCount*3); - DEBUG_ASSERTCRASH(ibSlot != NULL, ("Can't allocate index buffer slot for shadow volume")); - if (ibSlot != NULL) + // Check if index buffer allocation failed or is too small + if (ibSlot == NULL || ibSlot->m_size < (polygonCount*3)) { - DEBUG_ASSERTCRASH(ibSlot->m_size >= (polygonCount*3),("Overflowing Shadow Index Buffer Slot")); - } - - if (!ibSlot || !vbSlot) - { //could not allocate storage to hold buffers + // Shadow volume too complex for available buffers - skip rendering instead of crashing if (ibSlot) TheW3DBufferManager->releaseSlot(ibSlot); if (vbSlot) TheW3DBufferManager->releaseSlot(vbSlot); - - m_shadowVolumeIB[ volumeIndex ][meshIndex]=NULL; - m_shadowVolumeVB[ volumeIndex ][meshIndex]=NULL; + m_shadowVolumeIB[ volumeIndex ][meshIndex] = NULL; + m_shadowVolumeVB[ volumeIndex ][meshIndex] = NULL; return; } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp index d6eaa6030fe..e2d15ba685b 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp @@ -1360,19 +1360,24 @@ void W3DVolumetricShadow::RenderMeshVolume(Int meshIndex, Int lightIndex, const W3DBufferManager::W3DVertexBufferSlot *vbSlot=m_shadowVolumeVB[lightIndex][ meshIndex ]; if (!vbSlot) return; + + // Check if buffer is too small - skip rendering if shadow is too complex + if (vbSlot->m_size < numVerts) + return; + if (vbSlot->m_VB->m_DX8VertexBuffer->Get_DX8_Vertex_Buffer() != lastActiveVertexBuffer) { lastActiveVertexBuffer=vbSlot->m_VB->m_DX8VertexBuffer->Get_DX8_Vertex_Buffer(); m_pDev->SetStreamSource(0,lastActiveVertexBuffer, vbSlot->m_VB->m_DX8VertexBuffer->FVF_Info().Get_FVF_Size()); //12 bytes per vertex. } - DEBUG_ASSERTCRASH(vbSlot->m_size >= numVerts,("Overflowing Shadow Vertex Buffer Slot")); - W3DBufferManager::W3DIndexBufferSlot *ibSlot=m_shadowVolumeIB[lightIndex][ meshIndex ]; if (!ibSlot) return; - DEBUG_ASSERTCRASH(ibSlot->m_size >= numIndex,("Overflowing Shadow Index Buffer Slot")); + // Check if buffer is too small - skip rendering if shadow is too complex + if (ibSlot->m_size < numIndex) + return; m_pDev->SetIndices(ibSlot->m_IB->m_DX8IndexBuffer->Get_DX8_Index_Buffer(),vbSlot->m_start); @@ -2938,10 +2943,14 @@ void W3DVolumetricShadow::constructVolumeVB( Vector3 *lightPosObject,Real shadow vbSlot=m_shadowVolumeVB[ volumeIndex ][meshIndex] = TheW3DBufferManager->getSlot(W3DBufferManager::VBM_FVF_XYZ, vertexCount); - DEBUG_ASSERTCRASH(vbSlot != NULL, ("Can't allocate vertex buffer slot for shadow volume")); - if (vbSlot != NULL) + // Check if vertex buffer allocation failed or is too small + if (vbSlot == NULL || vbSlot->m_size < vertexCount) { - DEBUG_ASSERTCRASH(vbSlot->m_size >= vertexCount,("Overflowing Shadow Vertex Buffer Slot")); + // Shadow volume too complex for available buffers - skip rendering instead of crashing + if (vbSlot) + TheW3DBufferManager->releaseSlot(vbSlot); + m_shadowVolumeVB[ volumeIndex ][meshIndex] = NULL; + return; } DEBUG_ASSERTCRASH(m_shadowVolume[ volumeIndex ][meshIndex]->GetNumPolygon() == 0,("Updating Existing Static Shadow Volume")); @@ -2949,21 +2958,16 @@ void W3DVolumetricShadow::constructVolumeVB( Vector3 *lightPosObject,Real shadow DEBUG_ASSERTCRASH(m_shadowVolumeIB[ volumeIndex ][meshIndex] == NULL,("Updating Existing Static Index Buffer Shadow")); ibSlot=m_shadowVolumeIB[ volumeIndex ][meshIndex] = TheW3DBufferManager->getSlot(polygonCount*3); - DEBUG_ASSERTCRASH(ibSlot != NULL, ("Can't allocate index buffer slot for shadow volume")); - if (ibSlot != NULL) + // Check if index buffer allocation failed or is too small + if (ibSlot == NULL || ibSlot->m_size < (polygonCount*3)) { - DEBUG_ASSERTCRASH(ibSlot->m_size >= (polygonCount*3),("Overflowing Shadow Index Buffer Slot")); - } - - if (!ibSlot || !vbSlot) - { //could not allocate storage to hold buffers + // Shadow volume too complex for available buffers - skip rendering instead of crashing if (ibSlot) TheW3DBufferManager->releaseSlot(ibSlot); if (vbSlot) TheW3DBufferManager->releaseSlot(vbSlot); - - m_shadowVolumeIB[ volumeIndex ][meshIndex]=NULL; - m_shadowVolumeVB[ volumeIndex ][meshIndex]=NULL; + m_shadowVolumeIB[ volumeIndex ][meshIndex] = NULL; + m_shadowVolumeVB[ volumeIndex ][meshIndex] = NULL; return; }