- bugfix for cell bad cell management in map preview

This commit is contained in:
Mark Vejvoda
2010-09-13 23:10:29 +00:00
parent 40489e0687
commit f373a7f9bb
2 changed files with 21 additions and 10 deletions

View File

@@ -2635,7 +2635,8 @@ void MenuStateCustomGame::cleanupFactionTexture() {
MapPreview::MapPreview() { MapPreview::MapPreview() {
altFactor = 3; altFactor = 3;
waterLevel = 4; waterLevel = 4;
cells = NULL; //cells = NULL;
cells.clear();
startLocations = NULL; startLocations = NULL;
reset(128, 128, 10.f, 1); reset(128, 128, 10.f, 1);
resetFactions(8); resetFactions(8);
@@ -2650,13 +2651,15 @@ MapPreview::~MapPreview() {
startLocations = NULL; startLocations = NULL;
if(hasFileLoaded() == true) { if(hasFileLoaded() == true) {
for (int i = 0; i < h; i++) { //for (int i = 0; i < h; i++) {
delete [] cells[i]; // delete [] cells[i];
} //}
delete [] cells; //delete [] cells;
fileLoaded = false; fileLoaded = false;
} }
cells = NULL; //cells = NULL;
cells.clear();
} }
@@ -2709,20 +2712,26 @@ void MapPreview::reset(int w, int h, float alt, int surf) {
return; return;
} }
/*
if (cells != NULL) { if (cells != NULL) {
for (int i = 0; i < this->w; i++) { for (int i = 0; i < this->w; i++) {
delete [] cells[i]; delete [] cells[i];
} }
delete [] cells; delete [] cells;
} }
*/
cells.clear();
this->w = w; this->w = w;
this->h = h; this->h = h;
this->maxFactions = maxFactions; this->maxFactions = maxFactions;
cells = new Cell*[w]; cells.resize(w);
//cells = new Cell*[w];
for (int i = 0; i < w; i++) { 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++) { for (int j = 0; j < h; j++) {
cells[i][j].height = alt; cells[i][j].height = alt;
cells[i][j].object = 0; cells[i][j].object = 0;
@@ -2762,7 +2771,8 @@ int MapPreview::getWaterLevel() const {
void MapPreview::loadFromFile(const string &path) { void MapPreview::loadFromFile(const string &path) {
altFactor = 3; altFactor = 3;
waterLevel = 4; waterLevel = 4;
cells = NULL; //cells = NULL;
cells.clear();
startLocations = NULL; startLocations = NULL;
reset(128, 128, 10.f, 1); reset(128, 128, 10.f, 1);
resetFactions(8); resetFactions(8);

View File

@@ -64,7 +64,8 @@ private:
int w; int w;
int altFactor; int altFactor;
int waterLevel; int waterLevel;
Cell **cells; //Cell **cells;
std::vector<std::vector<Cell> > cells;
int maxFactions; int maxFactions;
StartLocation *startLocations; StartLocation *startLocations;
int refAlt; int refAlt;