diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-09-28 14:49:02 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-09-28 14:49:02 +0000 |
commit | fc0b308983f9421861e508381f73a0605eeed5b7 (patch) | |
tree | 006abb350306972fcff2329f0ec9b8eb082faad7 /src/map.cpp | |
parent | 32e570d5a5ab3faa36c47c8c3eea491518178a05 (diff) | |
download | mana-fc0b308983f9421861e508381f73a0605eeed5b7.tar.gz mana-fc0b308983f9421861e508381f73a0605eeed5b7.tar.bz2 mana-fc0b308983f9421861e508381f73a0605eeed5b7.tar.xz mana-fc0b308983f9421861e508381f73a0605eeed5b7.zip |
Fix random crashes when map tiles are missing.
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
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 |