I'm making a .json loader for a project that I'm working on, and to simplify things, I decided to make all the root attributes named in a separate file. Here's my problem: my loading function,
Add(const char* id)
, works just fine when I pass it a string literal. However, when I use a function that iterates through a vector list, even with the exact same definitions as the literal, it returns the error:
std::out_of_range at memory location 0x0026fb30
I cannot, for my life and love of it, figure out what is going wrong. I've stepped through it with the VS2010 debugger about a hundred times, checked against memory locations, and just have done everything I can think of, all to no avail. If anybody can offer some insight, it would be greatly appreciated.
The code, with data-checking omitted:
The std::map I'm adding to:
|
static std::map<const char*, Item*> *s_mItems;
|
Initialized as
std::map<const char*, Item*> *Item::s_mItems;
Add() Function (Works by itself with a literal):
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
static bool Add(const char* id)
{
...
std::string name = node.Get("name").ToString();
std::string desc = node.Get("description").ToString();
int rarity = StrToRarity(node.Get("rarity").ToString());
int price = node.Get("price").ToInt();
Item *_temp = new Item(name.c_str(), desc.c_str(), rarity, price);
std::pair<const char*, Item*> temp(id, _temp);
s_mItems->insert(temp);
printf("[INFO] Added item '%s' with id '%s'.\n", name.c_str(), id);
...
}
|
AddList() function, where the program always breaks:
1 2 3 4 5 6 7
|
static void AddList(std::vector<std::string> list)
{
for(std::vector<std::string>::iterator it = list.begin(); it != list.end(); it++)
{
Add(it->c_str());
}
}
|