Skip to content

Commit

Permalink
Fix curVertexCount/curIndexCount overflow on Error
Browse files Browse the repository at this point in the history
  • Loading branch information
sultim-t committed Nov 12, 2023
1 parent 09d9662 commit 5f6e500
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Source/VertexCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ auto RTGL1::VertexCollector::Upload( VertexCollectorFilterTypeFlags geomFlags,
const bool useIndices = prim.indexCount != 0 && prim.pIndices != nullptr;
const uint32_t triangleCount = useIndices ? prim.indexCount / 3 : prim.vertexCount / 3;



if( curVertexCount + prim.vertexCount >= bufVertices.ElementCount() )
{
debug::Error( geomFlags & FT::CF_DYNAMIC ? "Too many dynamic vertices: the limit is {}"
: "Too many static vertices: the limit is {}",
bufVertices.ElementCount() );
return {};
}
if( curIndexCount + ( useIndices ? prim.indexCount : 0 ) >= bufIndices.ElementCount() )
{
debug::Error( "Too many indices: the limit is {}", bufIndices.ElementCount() );
return {};
}



// clang-format off
curVertexCount = vertIndex + ( prim.vertexCount );
curIndexCount = indIndex + ( useIndices ? prim.indexCount : 0 );
Expand All @@ -156,7 +173,6 @@ auto RTGL1::VertexCollector::Upload( VertexCollectorFilterTypeFlags geomFlags,
curTexCoordCount_Layer3 = texcIndex_3 + ( GeomInfoManager::LayerExists( prim, 3 ) ? prim.vertexCount : 0 );
// clang-format on


if( resultRanges )
{
*resultRanges = CopyRanges{
Expand All @@ -169,22 +185,6 @@ auto RTGL1::VertexCollector::Upload( VertexCollectorFilterTypeFlags geomFlags,
}


{
if( curVertexCount >= bufVertices.ElementCount() )
{
debug::Error( geomFlags & FT::CF_DYNAMIC ? "Too many dynamic vertices: the limit is {}"
: "Too many static vertices: the limit is {}",
bufVertices.ElementCount() );
return {};
}
if( curIndexCount >= bufIndices.ElementCount() )
{
debug::Error( "Too many indices: the limit is {}", bufIndices.ElementCount() );
return {};
}
}



// copy data to buffers
CopyVertexDataToStaging( prim, vertIndex, texcIndex_1, texcIndex_2, texcIndex_3 );
Expand Down

0 comments on commit 5f6e500

Please sign in to comment.