The function listener(TCODMap & map, Engine & engine) of my BSPListener class will never execute because calling *this as a parameter causes an unhandled exception error.(The call using *this is in initializeMap()).
In Engine.cpp
void Engine::initializeMap()
{
float maxHratio = rand() % 10 + 1;
float maxVratio = rand() % 10 + 1;
int nbRecursions = rand() % 10 + 1;
maps.push_back(TCODMap(70,40));
for (int x = 0; x < maps[currentMap].getWidth() ; x++)
{
for (int y = 0; y < maps[currentMap].getHeight() - 1; y++)
{
//Set all cells to unwalkable and transparent
maps[currentMap].setProperties(x, y, true, false);
}
}
TCODBsp bsp(0, 0, maps[currentMap].getWidth(), maps[currentMap].getHeight());
bsp.splitRecursive(NULL, nbRecursions, ROOM_MAX_SIZE, ROOM_MAX_SIZE, maxHratio, maxVratio);
BspListener listener(maps.at(currentMap), *this);
bsp.traverseInvertedLevelOrder(&listener, NULL);
for (int x = 0; x < this->maps[currentMap].getWidth(); x++)
{
for (int y = 0; y < maps[currentMap].getHeight(); y++)
{
if (maps[currentMap].isWalkable(x, y))
{
std::tuple<int, int> temp = std::make_tuple(x, y);
std::cout << "Valid spawn point at (" << x << ", " << y << ")" << std::endl;
walkableCells.push(temp);
}
}
}
}
In BspListener.h
bool visitNode(TCODBsp* node, void* userData)
{
//std::cout << "visited node";
if (node->isLeaf())
{
int x, y, w, h;//w is width, h is height
TCODRandom* rng = TCODRandom::getInstance();
w = rng->getInt(ROOM_MIN_SIZE, node->w - 2);
h = rng->getInt(ROOM_MIN_SIZE, node->h - 2);
x = rng->getInt(node->x + 1, node->x + node->w - w - 1);
y = rng->getInt(node->y + 1, node->y + node->h - h - 1);
engine.digRoom(roomNum == 0, x, y, x + w - 1, y + h - 1);//Dont create corridor from nowhere if it is the first room
if(roomNum != 0)
{
engine.dig(lastx, lasty, x + w / 2, lasty);
engine.dig(x + w / 2, lasty, x + w / 2, y + h / 2);
}
lastx = x + w / 2;
lasty = y + h / 2;
roomNum++;
}
return true;
}
I get this exception at listener()
Exception thrown at 0x00007FF8D032EFBB (ntdll.dll) in Huronia.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
Any ideas as to why this might be? I wasn't having this error when I was just using a single TCODMap object. Now that I've made it so we have an array of those objects, this simply doesn't work. All I really want to know is how I should go about changing the function.
User contributions licensed under CC BY-SA 3.0