Index: viewport.c =================================================================== --- viewport.c (revision 6250) +++ viewport.c (working copy) @@ -297,6 +297,7 @@ { Point pt; int a,b; + uint maxx, maxy; if ( (uint)(x -= vp->left) >= (uint)vp->width || (uint)(y -= vp->top) >= (uint)vp->height) { @@ -315,7 +316,19 @@ b = x-y; #endif - if ((uint)a < MapMaxX() * TILE_SIZE && (uint)b < MapMaxY() * TILE_SIZE) { + maxx = MapMaxX() * TILE_SIZE; + maxy = MapMaxY() * TILE_SIZE; + + /* we need to move variables in to the valid range if they happen to be outside as + GetTileZoomCenterWindow() can call here with invalid x and/or y if the user tries + to zoom out along the sides of the map */ + if ((uint)a >= maxx) { + if (a < 0) a = 0; else a = ((int)maxx) - 1; + } + if ((uint)b >= maxy) { + if (b < 0) b = 0; else b = ((int)maxy) - 1; + } + uint z; z = GetSlopeZ(a, b ) / 2; @@ -326,9 +339,6 @@ pt.x = a + z; pt.y = b + z; - } else { - pt.x = pt.y = -1; - } return pt; }