Getting 0xC0000005 Access Violation Error and unsure how to fix it


I added a method to my Zork program to randomly move the enemies in the game when ever the player moves. I did this by first checking if the enemy can roam. The move method shuffles an array of directions and loops through the array and the enemy goes in that direction if it doesn't lead to a nullptr (a wall). But after a couple moves the program exits. Still quite new to C++ and all of its memory allocation etiquette. Also looking for a better way to randomly move the enemies. Thanks! The go method reads in a direction and changes the players current room to the room in that direction if it is not a nullptr.

void Game::go(string direction) {
    Room *next = player.getCurrentRoom()->getExit(direction);

    if (next != nullptr) {
        if (!next->lockCheck(next)) {        //check for no lock on door
            player.setStamina(player.getStamina() - 1);
            EventManager::getInstance().trigger("enterRoom", next);
            for (auto &enemy : enemies) {
                if (enemy->roamingCheck(enemy)) {
                    enemy->setStamina(enemy->getStamina() - 1);

void Character::Move(Character *enemy) {
    Room *next;
    for(int i = 0; i < directions->size() - 1; i++) {
        int j = i + rand() % (directions->size() - i);      //Shuffle array of directions
        std::swap(directions[i], directions[j]);
    for(int i = 0; i < directions->size(); i++) {
        if(enemy->getCurrentRoom()->getExit(directions[i]) != nullptr) {
            next = enemy->getCurrentRoom()->getExit(directions[i]);

asked on Stack Overflow Apr 18, 2020 by Mikel112543

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0