Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -2794,32 +2799,31 @@ 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"));

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -2938,32 +2943,31 @@ 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"));

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;
}

Expand Down
Loading