Skip to content
Open
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
14 changes: 14 additions & 0 deletions Core/GameEngine/Source/Common/System/Radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ void Radar::newMap( TerrainLogic *terrain )
m_xSample = m_mapExtent.width() / RADAR_CELL_WIDTH;
m_ySample = m_mapExtent.height() / RADAR_CELL_HEIGHT;

// prevent division by zero if map has invalid dimensions
if( m_xSample <= 0.0f )
m_xSample = 1.0f;
if( m_ySample <= 0.0f )
m_ySample = 1.0f;

// find the "middle" height for the terrain (most used value) and water table
Int x, y;
Int terrainSamples = 0, waterSamples = 0;
Expand Down Expand Up @@ -512,6 +518,10 @@ Bool Radar::radarToWorld2D( const ICoord2D *radar, Coord3D *world )
if( radar == NULL || world == NULL )
return FALSE;

// prevent invalid calculations with zero sample rates
if( m_xSample <= 0.0f || m_ySample <= 0.0f )
return FALSE;

// get the coords
x = radar->x;
y = radar->y;
Expand Down Expand Up @@ -562,6 +572,10 @@ Bool Radar::worldToRadar( const Coord3D *world, ICoord2D *radar )
if( world == NULL || radar == NULL )
return FALSE;

// prevent division by zero
if( m_xSample <= 0.0f || m_ySample <= 0.0f )
return FALSE;

// sanity check the world position
// if( world->x < m_mapExtent.lo.x || world->x > m_mapExtent.hi.x ||
// world->y < m_mapExtent.lo.y || world->y > m_mapExtent.hi.y )
Expand Down
Loading