0

I am currently using C++ with Direct3D and am trying to alter my asset storage.

Right now my assets are stored as "vector textureList" and are obtained using enumerated definitions.

I wanted to make the class more open by using the STL map class. However, I have never used this class before and I am running into problems that I just don't understand.

I have just made everything pretty bare-bones to test and currently have the following:

#include <d3d9.h>
#include <d3dx9.h>
#include <map>
#include <string>

#pragma comment (lib, "d3d9.lib") 
#pragma comment (lib, "d3dx9.lib") 

using namespace std;


class Assets
{
private:
typedef std::map<string, IDirect3DTexture9*> TexMap;
TexMap textureList;

public:
IDirect3DTexture9* LoadTexture(IDirect3DDevice9* pd3dDevice, LPCWSTR file, string key)
{     
    //load a texture from file
    IDirect3DTexture9*      tex;


    //D3DXCreateTextureFromFile(pd3dDevice, file, &tex);
    D3DXCreateTextureFromFileEx(pd3dDevice, file, 512, 512, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0xFF000000, NULL, NULL, &tex);


    //store the loaded texture to a vector array
    textureList.insert(TexMap::value_type(key, tex));
    return S_OK;
}
}

When I try to run this I get a "Debug Assertion Failed" error with the expression "map/set iterators incompatible"

I just feel I have made this as simple as a can in the code and still cannot see the error from looking at similar examples.

I have also run the code as:

#include <d3d9.h>
#include <d3dx9.h>
#include <map>
#include <string>

#pragma comment (lib, "d3d9.lib") 
#pragma comment (lib, "d3dx9.lib") 

using namespace std;

class Assets
{
private:
typedef std::map<int, int> TexMap;
TexMap textureList;

public:

IDirect3DTexture9* LoadTexture(IDirect3DDevice9* pd3dDevice, LPCWSTR file, string key)
    {     

    //load a texture from file
    IDirect3DTexture9*      tex;


    //D3DXCreateTextureFromFile(pd3dDevice, file, &tex);
    D3DXCreateTextureFromFileEx(pd3dDevice, file, 512, 512, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0xFF000000, NULL, NULL, &tex);


    //store the loaded texture to a vector array
    //textureList.push_back(tex);
    textureList.insert(TexMap::value_type(3, 4));
    return S_OK;
}
}

Just so it is simply using ints and I still get the same error.

user1539405
  • 111
  • 1
  • 14
  • What's the calling code? There's no `main` in there. My guess is that you're invalidating an iterator somewhere. – netcoder Aug 08 '12 at 19:33
  • Yes, at the moment the main function loads the scene manager and the scene manage creates the asset class. I'll add the code for the main and any relevant sections to the first post. How might an iterator become invalid? – user1539405 Aug 08 '12 at 20:08
  • See [Iterator invalidation rules](http://stackoverflow.com/questions/6438086/iterator-invalidation-rules). – netcoder Aug 08 '12 at 20:11
  • Doh, I was using ZeroMemory on the map. I literally replaced the vector and map with the same variable name so I never removed that. Honesly I didn't need the ZeroMemory, it was part of another bug I was trying to fix. Ok, problem solved :P – user1539405 Aug 08 '12 at 20:30

1 Answers1

0

The error might be pretty basic actually--D3DXCreateTextureFromFileEx wants type IDirect3DTexture9* for its last argument, but you're giving it type IDirect3DTexture9**. That is, change

D3DXCreateTextureFromFileEx(..., &tex);

to

D3DXCreateTextureFromFileEx(..., tex);
Matt Phillips
  • 9,465
  • 8
  • 44
  • 75
  • actually the function is after IDirect3DTexture9** (or more specifically "LPDIRECT3DTEXTUR9 *ppTexture"). Aside from that the textures load fine when I am using my vector-based storage. Thank you though. – user1539405 Aug 08 '12 at 20:06
  • Considering nothing in this function call uses the `map` at all, I doubt this is the problem. – netcoder Aug 08 '12 at 20:12