0

我目前正在将 C++ 与 Direct3D 一起使用,并正在尝试更改我的资产存储。

现在我的资产存储为“矢量纹理列表”,并使用枚举定义获得。

我想通过使用 STL 地图类使课程更加开放。但是,我以前从未使用过这个类,并且遇到了我不理解的问题。

我刚刚做了一切非常简单的测试,目前有以下内容:

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

当我尝试运行它时,出现“调试断言失败”错误,表达式为“map/set iterators incompatible”

我只是觉得我在代码中做到了尽可能简单,但通过查看类似示例仍然看不到错误。

我还将代码运行为:

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

就这样它只是使用整数,我仍然得到同样的错误。

4

1 回答 1

0

该错误实际上可能非常基本 -D3DXCreateTextureFromFileEx想要 typeIDirect3DTexture9*作为最后一个参数,但你给它 type IDirect3DTexture9**。也就是改变

D3DXCreateTextureFromFileEx(..., &tex);

D3DXCreateTextureFromFileEx(..., tex);
于 2012-08-08T19:48:51.490 回答