With an insane number of units or effects, it's possible to get the polygon count to overflow a 16 bit limit and subsequently crash the game. This needs fixing, but the scenario is somewhat contrived because the game is so slow it's completely unplayable by the time it overflows and crashes. There's an assertion that'll get triggered in debug mode.
|
unsigned polygonAllocCount = overlapping_polygon_count; |
|
if ((unsigned)(DynamicIBAccessClass::Get_Default_Index_Count()/3) < DEFAULT_SORTING_POLY_COUNT) |
|
polygonAllocCount = DEFAULT_SORTING_POLY_COUNT; //make sure that we force the DX8 index buffer to maximum size |
|
if (overlapping_polygon_count > polygonAllocCount) |
|
polygonAllocCount = overlapping_polygon_count; |
|
WWASSERT(DEFAULT_SORTING_POLY_COUNT <= 1 || polygonAllocCount <= DEFAULT_SORTING_POLY_COUNT); |
|
|
|
DynamicIBAccessClass dyn_ib_access(BUFFER_TYPE_DYNAMIC_DX8,polygonAllocCount*3); |
|
{ |
|
DynamicIBAccessClass::WriteLockClass lock(&dyn_ib_access); |
|
ShortVectorIStruct* sorted_polygon_index_array=(ShortVectorIStruct*)lock.Get_Index_Array(); |
|
|
|
for (unsigned a=0;a<overlapping_polygon_count;++a) { |
|
sorted_polygon_index_array[a]=tis[a].tri; |
|
} |
|
} |
A couple of issues here:
polygonAllocCount*3 (L534) is cast to an unsigned short by DynamicIBAccessClass's constructor, so it must below 2 ^ 16 considering it's used later for the iteration.
a<overlapping_polygon_count (L539) should be a<polygonAllocCount.
With an insane number of units or effects, it's possible to get the polygon count to overflow a 16 bit limit and subsequently crash the game. This needs fixing, but the scenario is somewhat contrived because the game is so slow it's completely unplayable by the time it overflows and crashes. There's an assertion that'll get triggered in debug mode.
GeneralsGameCode/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp
Lines 527 to 542 in fc36efc
A couple of issues here:
polygonAllocCount*3(L534) is cast to anunsigned shortbyDynamicIBAccessClass's constructor, so it must below 2 ^ 16 considering it's used later for the iteration.a<overlapping_polygon_count(L539) should bea<polygonAllocCount.