From f373a7f9bb86a7cd8cc3157abdc46abd25ce7eaf Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 13 Sep 2010 23:10:29 +0000 Subject: [PATCH] - bugfix for cell bad cell management in map preview --- .../menu/menu_state_custom_game.cpp | 28 +++++++++++++------ .../glest_game/menu/menu_state_custom_game.h | 3 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 5bd101bf..85cb1ca8 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2635,7 +2635,8 @@ void MenuStateCustomGame::cleanupFactionTexture() { MapPreview::MapPreview() { altFactor = 3; waterLevel = 4; - cells = NULL; + //cells = NULL; + cells.clear(); startLocations = NULL; reset(128, 128, 10.f, 1); resetFactions(8); @@ -2650,13 +2651,15 @@ MapPreview::~MapPreview() { startLocations = NULL; if(hasFileLoaded() == true) { - for (int i = 0; i < h; i++) { - delete [] cells[i]; - } - delete [] cells; + //for (int i = 0; i < h; i++) { + // delete [] cells[i]; + //} + //delete [] cells; + fileLoaded = false; } - cells = NULL; + //cells = NULL; + cells.clear(); } @@ -2709,20 +2712,26 @@ void MapPreview::reset(int w, int h, float alt, int surf) { return; } + /* if (cells != NULL) { for (int i = 0; i < this->w; i++) { delete [] cells[i]; } delete [] cells; } + */ + cells.clear(); this->w = w; this->h = h; this->maxFactions = maxFactions; - cells = new Cell*[w]; + cells.resize(w); + + //cells = new Cell*[w]; for (int i = 0; i < w; i++) { - cells[i] = new Cell[h]; + //cells[i] = new Cell[h]; + cells[i].resize(h); for (int j = 0; j < h; j++) { cells[i][j].height = alt; cells[i][j].object = 0; @@ -2762,7 +2771,8 @@ int MapPreview::getWaterLevel() const { void MapPreview::loadFromFile(const string &path) { altFactor = 3; waterLevel = 4; - cells = NULL; + //cells = NULL; + cells.clear(); startLocations = NULL; reset(128, 128, 10.f, 1); resetFactions(8); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index f7d9efa5..8cf5b195 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -64,7 +64,8 @@ private: int w; int altFactor; int waterLevel; - Cell **cells; + //Cell **cells; + std::vector > cells; int maxFactions; StartLocation *startLocations; int refAlt;