I have a std::unordered_map as part of a global variable of a struct type:
typedef struct level_locals_s {
std::unordered_map<std::string, std::string> spawnVars;
...
} level_locals_t;
level_locals_t level;
...
...
void AddSpawnFields( char *key, char *value ) {
level.spawnVars.insert(std::make_pair<std::string, std::string>(key, value);
}
The program crashes upon the insert. I have checked, and the key/value are correct. Here's where it crashes:
iterator begin()
{ // return iterator for beginning of mutable sequence
return (iterator(this->_Nextnode(this->_Myhead), this));
}
this->_Myhead appears to be NULL. What would be the cause of this?
Using Microsoft Visual C++ 2010. 0xC0000005: Access violation reading location 0x00000000 is the error.
EDIT: Here is a compilable example:
#include <stdio.h>
#include <string>
#include <unordered_map>
using namespace std;
typedef struct level_locals_s
{
unordered_map<string, string> spawnArgs;
} level_locals_t;
level_locals_t level;
void main(char **args, int argc)
{
string st1 = "key";
string st2 = "value";
memset(&level, 0, sizeof(level));
level.spawnArgs.insert(pair<string, string>(st1, st2));
}