From c52e734ca43238cf8f4f5fdae8c4de55c60ae1ad Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Sun, 11 Jan 2026 10:34:53 +0000 Subject: [PATCH] Fix radar division by zero with invalid map dimensions --- Core/GameEngine/Source/Common/System/Radar.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Core/GameEngine/Source/Common/System/Radar.cpp b/Core/GameEngine/Source/Common/System/Radar.cpp index 86ac2046b84..58141e7edae 100644 --- a/Core/GameEngine/Source/Common/System/Radar.cpp +++ b/Core/GameEngine/Source/Common/System/Radar.cpp @@ -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; @@ -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; @@ -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 )