From abff8d12c4d76c4fddff1bed485334833bdc4597 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Mon, 12 Jul 2004 16:08:41 +0000 Subject: [PATCH] Don't crash when units exist off the map This was SVN commit r726. --- source/simulation/Entity.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index f820ac5847..cc40128f79 100755 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -128,6 +128,12 @@ float CEntity::getExactGroundLevel( float x, float y ) assert( ( xi >= 0 ) && ( xi < (int)mapsize ) && ( yi >= 0 ) && ( yi < (int)mapsize ) ); + // In non-debug builds, do something nicer than crashing + if (! ( ( xi >= 0 ) && ( xi < (int)mapsize ) && ( yi >= 0 ) && ( yi < (int)mapsize ) ) ) + { + return 0.0f; + } + float h00 = heightmap[yi*mapsize + xi]; float h01 = heightmap[yi*mapsize + xi + mapsize]; float h10 = heightmap[yi*mapsize + xi + 1];