My map::insert method is breaking, without giving me a lot of useful information.
typedef map<wstring, int> IndexLookupMap;
static IndexLookupMap indexLookup;
static vector<LPDIRECT3DTEXTURE9> textures;
extern "C" void EXPORT_API LoadTexture(const wchar_t* file, int* index, unsigned char* data) {
wstring key(file);
if(indexLookup.size() > 0)
{
IndexLookupMap::iterator it = indexLookup.find(key);
if(it == indexLookup.end())
{
//not found, load it
LPDIRECT3DTEXTURE9 pTexture;
D3DXCreateTextureFromFile(g_D3D9Device, file, &pTexture);
textures.push_back(pTexture);
*index = textures.size() - 1;
D3DLOCKED_RECT locked;
pTexture->LockRect(0, &locked, NULL, 0);
data = reinterpret_cast<unsigned char*>(locked.pBits);
pTexture->UnlockRect(0);
indexLookup.insert(IndexLookupMap::value_type(key, *index));
}
else
{
//found, get it
*index = it->second;
textures.at(*index);
}
}
else
{
//not found, load it
LPDIRECT3DTEXTURE9 pTexture;
D3DXCreateTextureFromFile(g_D3D9Device, file, &pTexture);
textures.push_back(pTexture);
*index = textures.size() - 1;
D3DLOCKED_RECT locked;
pTexture->LockRect(0, &locked, NULL, 0);
data = reinterpret_cast<unsigned char*>(locked.pBits);
pTexture->UnlockRect(0);
indexLookup.insert(IndexLookupMap::value_type(key, *index)); //breaks here
}
}
It is breaking on:
indexLookup.insert(IndexLookupMap::value_type(key, *index));
The actual break occurs in xtree:
_Nodeptr _Trynode = _Root();