Skip to content

Commit

Permalink
Fix resize operating on the cache and data. Because the array copy is…
Browse files Browse the repository at this point in the history
… single dimension, we have to iterate by columns, and not rows.
  • Loading branch information
ShadoMagi committed Oct 30, 2020
1 parent b87cac1 commit 7de8a11
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions MornaMapEditor/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ public void ResizeMap(Size newSize)
IsModified = true;
mapData = new Tile[Size.Width, Size.Height];
mapCache = new Bitmap[Size.Width, Size.Height];
// Copy rows up to the size of the smaller height of the two arrays. A row is the size of the smaller width of the two arrays
// Copy columns up to the size of the smaller width of the two arrays. A row is the size of the smaller height of the two arrays
// We will either let the end fill with null or we are pruning
for (int y = 0; y < Math.Min(oldSize.Height, newSize.Height); y++)
for (int x = 0; x < Math.Min(oldSize.Width, newSize.Width); x++)
{
var startIndexOld = oldSize.Width * y;
var startIndexNew = Size.Width * y;
Array.Copy(oldData, startIndexOld, mapData, startIndexNew, Math.Min(oldSize.Width, Size.Width));
Array.Copy(oldCache, startIndexOld, mapCache, startIndexNew, Math.Min(oldSize.Width, Size.Width));
var startIndexOld = oldSize.Height * x;
var startIndexNew = Size.Height * x;
Array.Copy(oldData, startIndexOld, mapData, startIndexNew, Math.Min(oldSize.Height, Size.Height));
Array.Copy(oldCache, startIndexOld, mapCache, startIndexNew, Math.Min(oldSize.Height, Size.Height));
}
}

Expand Down

0 comments on commit 7de8a11

Please sign in to comment.