EXC_BAD_ACCESS for assignment of ID to Tile object

58 views Asked by At

The implementation for a Tile object (an array of which forms a map object) is as follows

#include "Tile.h"

Tile::Tile(){
    isPassable_ = true;
}

void Tile::setID(int ID){
    ID_ = ID;
    Tile::setVals(ID);
}

void Tile::setVals(int ID){
    switch(ID){
        case 1 : Tile::GFX_ = '.'; Tile::name_ = "Grass"; Tile::desc_ = "Some grass";
        default: Tile::GFX_ = '?'; Tile::name_ = "Error"; Tile::desc_ = "Error"; Tile::isPassable_ = false;
    }
}

int Tile::getID(){return ID_;}
char Tile::getGFX(){return GFX_;}
std::string Tile::getName(){return name_;}
std::string Tile::getDesc(){return desc_;}
bool Tile::getIsPassable(){return isPassable_;}

Where HEIGHT and WIDTH are constant ints defined in the Map header. However, when the program runs, I receive an error for ID_ = ID; saying "Thread 1: EXC_BAD_ACCESS(code=1,address=0x0). Could this be a problem with the way that I'm accessing the Tile objects in its 2D array in the Map object, as follows

#include "Map.h"

Map::Map(int buffMap[][WIDTH]){
    for(int y = 0; y < HEIGHT-1; y++){
        for(int x = 0; x < WIDTH-1; x++){
            map_[y][x]->setID(1);
        }
    }
    for(int y = 0; y < HEIGHT-1; y++){
        for(int x = 0; x < WIDTH-1; x++){
            map_[y][x]->setID(buffMap[y][x]);
        }
    }
}

Thanks!

0

There are 0 answers