Nicolas Charvoz
Nicolas Charvoz

Reputation: 1509

std::map::operator[] Violation access memory on windows

I'm having a big issue on one of my project. This project is cross-platform. It works just fine on Linux, but on windows I have a Violation access memory when filling a map.

My main.cpp looks like this :

Server *s = new Server;

s->init(4253);

SERVER.CPP :

this->_commandManager.addFunction(C_CREATEROOM, &Server::createRoom);
this->_commandManager.addFunction(C_JOINROOM, &Server::joinRoom);
this->_commandManager.addFunction(C_LAUNCHGAME, &Server::createGame);

And finally my CommandManager :

bool CommandManager::addFunction(E_COMMAND type, bool (Server::*cmd)(ANetwork::t_frame frame, void *data))
{
  _commands[type] = cmd;

  return true;
}

_commands is type of std::map<E_COMMAND, bool (Server::*)(ANetwork::t_frame, void*)>

Adding cmd to _commands[type] works fine on Linux (ubuntu and opensuse) but throw a Violation Access Memory on Windows 10 with VS Entreprise 2015.

Upvotes: 1

Views: 73

Answers (1)

Antoine Garcia
Antoine Garcia

Reputation: 143

If you are using VS, try to use /vmg option in your compilator.

Upvotes: 1

Related Questions