prevent overflow in gridsize adjustment
This commit is contained in:
parent
15b391cdb3
commit
a743668e44
|
|
@ -1662,9 +1662,8 @@ void SetupGrid( void ){
|
||||||
gridSize[ i ] = std::max( 8.0, floor( gridSize[ i ] ) );
|
gridSize[ i ] = std::max( 8.0, floor( gridSize[ i ] ) );
|
||||||
|
|
||||||
/* ydnar: increase gridSize until grid count is smaller than max allowed */
|
/* ydnar: increase gridSize until grid count is smaller than max allowed */
|
||||||
numRawGridPoints = MAX_MAP_LIGHTGRID + 1;
|
|
||||||
j = 0;
|
j = 0;
|
||||||
while ( numRawGridPoints > MAX_MAP_LIGHTGRID )
|
while ( true )
|
||||||
{
|
{
|
||||||
/* get world bounds */
|
/* get world bounds */
|
||||||
for ( i = 0; i < 3; i++ )
|
for ( i = 0; i < 3; i++ )
|
||||||
|
|
@ -1674,13 +1673,17 @@ void SetupGrid( void ){
|
||||||
gridBounds[ i ] = ( max - gridMins[ i ] ) / gridSize[ i ] + 1;
|
gridBounds[ i ] = ( max - gridMins[ i ] ) / gridSize[ i ] + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set grid size */
|
const int64_t num = int64_t( gridBounds[ 0 ] ) * gridBounds[ 1 ] * gridBounds[ 2 ]; // int64_t prevents reachable int32_t overflow : cube( 131072 / 8 ) = 4398046511104
|
||||||
numRawGridPoints = gridBounds[ 0 ] * gridBounds[ 1 ] * gridBounds[ 2 ];
|
|
||||||
|
|
||||||
/* increase grid size a bit */
|
/* increase grid size a bit */
|
||||||
if ( numRawGridPoints > MAX_MAP_LIGHTGRID ) {
|
if ( num > MAX_MAP_LIGHTGRID ) {
|
||||||
gridSize[ j++ % 3 ] += 16.0f;
|
gridSize[ j++ % 3 ] += 16.0f;
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
/* set grid size */
|
||||||
|
numRawGridPoints = num;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print it */
|
/* print it */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user