diff options
Diffstat (limited to 'engines/toon/path.cpp')
-rw-r--r-- | engines/toon/path.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp index c116d63663..43a134e39b 100644 --- a/engines/toon/path.cpp +++ b/engines/toon/path.cpp @@ -342,8 +342,15 @@ next: curX = destx; curY = desty; - int32 retPathX[4096]; - int32 retPathY[4096]; + int32 *retPathX = (int32 *)malloc(4096 * sizeof(int32)); + int32 *retPathY = (int32 *)malloc(4096 * sizeof(int32)); + if (!retPathX || !retPathY) { + free(retPathX); + free(retPathY); + + error("[PathFinding::findPath] Cannot allocate pathfinding buffers"); + } + int32 numpath = 0; retPathX[numpath] = curX; @@ -377,8 +384,12 @@ next: } } - if (bestX < 0 || bestY < 0) + if (bestX < 0 || bestY < 0) { + free(retPathX); + free(retPathY); + return 0; + } retPathX[numpath] = bestX; retPathY[numpath] = bestY; @@ -389,6 +400,10 @@ next: memcpy(_tempPathX, retPathX, sizeof(int32) * numpath); memcpy(_tempPathY, retPathY, sizeof(int32) * numpath); + + free(retPathX); + free(retPathY); + return true; } @@ -396,6 +411,9 @@ next: curY = bestY; } + free(retPathX); + free(retPathY); + return false; } @@ -406,8 +424,8 @@ void PathFinding::init(Picture *mask) { _height = mask->getHeight(); _currentMask = mask; _heap->unload(); - // In order to reduce memory fragmentation on small devices, we use the maximum - // possible size here which is TOON_BACKBUFFER_WIDTH. Even though this is + // In order to reduce memory fragmentation on small devices, we use the maximum + // possible size here which is TOON_BACKBUFFER_WIDTH. Even though this is // 1280 as opposed to the possible 640, it actually helps memory allocation on // those devices. _heap->init(TOON_BACKBUFFER_WIDTH * _height); // should really be _width |