diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/map.cpp | 20 |
2 files changed, 18 insertions, 6 deletions
@@ -1,3 +1,7 @@ +2006-09-38 Björn Steinbrink <B.Steinbrink@gmx.de> + + * src/map.cpp: Fix random crashes when map tiles are missing. + 2006-09-28 Bjørn Lindeijer <bjorn@lindeijer.nl> * data/graphics/maps/new_2-1.tmx.gz: Matt Howe fixed up cave map. diff --git a/src/map.cpp b/src/map.cpp index 41282ddd..6277b424 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -63,8 +63,11 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): mOnClosedList(1), mOnOpenList(2), mLastScrollX(0.0f), mLastScrollY(0.0f) { - mMetaTiles = new MetaTile[mWidth * mHeight]; - mTiles = new Image*[mWidth * mHeight * 3]; + int size = mWidth * mHeight; + + mMetaTiles = new MetaTile[size]; + mTiles = new Image*[size * 3]; + std::fill_n(mTiles, size * 3, (Image*)0); } Map::~Map() @@ -86,12 +89,17 @@ Map::~Map() void Map::setSize(int width, int height) { - mWidth = width; - mHeight = height; delete[] mMetaTiles; delete[] mTiles; - mMetaTiles = new MetaTile[mWidth * mHeight]; - mTiles = new Image*[mWidth * mHeight * 3]; + + mWidth = width; + mHeight = height; + + int size = width * height; + + mMetaTiles = new MetaTile[size]; + mTiles = new Image*[size * 3]; + std::fill_n(mTiles, size * 3, (Image*)0); } void |