From acf4968253ed036e3a277ee8fe433c8490e43a5c Mon Sep 17 00:00:00 2001 From: Wanne Date: Thu, 25 Jul 2013 08:38:43 +0000 Subject: [PATCH] - HackFix: Crash on maps with isolated entry points (by silversurfer) o see http://www.ja-galaxy-forum.com/board/ubbthreads.php/topics/312260/Re_BUGZILLA_report_all_bugs_he.html#Post312260 o see http://www.ja-galaxy-forum.com/board/ubbthreads.php/topics/312612/Re_BUGZILLA_report_all_bugs_he.html#Post312612 o The main problem of the crash is, that some memory gets overwritten -> Workaround (hackfix): Increased the array for the map edgepoints to a fixed size of 400 so we can avoid the crash o Of course this is not the best fix (because of increased memory usage), so if someone can improve the fix, do it :) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6240 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- TileEngine/Map Edgepoints.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/TileEngine/Map Edgepoints.cpp b/TileEngine/Map Edgepoints.cpp index 2c445214..742d9e19 100644 --- a/TileEngine/Map Edgepoints.cpp +++ b/TileEngine/Map Edgepoints.cpp @@ -383,6 +383,13 @@ void InternallyClassifyEdgepoints( SOLDIERTYPE *pSoldier, INT32 sGridNo, { *psArray2 = (INT32*)MemAlloc( sizeof( INT32 ) * 400 ); } + // silversurfer: hackfix for crash on maps with isolated entry points + // we can't just keep adding data to psArray2 because it has only a fixed amount of memory available + // if we keep adding beyond that we overwrite foreign data! + // memory allocation for the real gps2ndEdgepointArray is done in function void GenerateMapEdgepoints(BOOLEAN fValidate) + // let's blow this up to some bigger amount, sizeof( INT32 ) * 400 will do for now + (*psArray2) = (INT32*)MemRealloc( (*psArray2), sizeof( INT32 ) * 400 ); + for( i = 0; i < *pusArraySize1; i++ ) { if( sGridNo == (*psArray1)[ i ] ) @@ -485,6 +492,7 @@ void InternallyClassifyEdgepoints( SOLDIERTYPE *pSoldier, INT32 sGridNo, } //Now compact the primary array, because some edgepoints have been removed. CompactEdgepointArray( psArray1, pusMiddleIndex1, pusArraySize1 ); + // silversurfer: this is the point where the editor will crash with a HeapValidate() error because we have been adding data beyond reserved memory (*psArray2) = (INT32*)MemRealloc( (*psArray2), *pusArraySize2 * sizeof( INT32 ) ); }