-1

私のmap::insertメソッドは、多くの有用な情報を提供せずに壊れています。

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
    }
}

それは壊れています:

indexLookup.insert(IndexLookupMap::value_type(key, *index));

実際のブレークはxtreeで発生します。

_Nodeptr _Trynode = _Root();
4

1 に答える 1

3

提供された最小限の情報に基づいて、が構築LoadTextureされる前に呼び出され、無効な状態になっていると思われます。map

于 2012-07-05T18:31:11.580 に答える