I have a class for my objects in my game engine. This class is:
class AStaticObject {
protected:
//Mesh
ID3DXMesh *g_pD3DXMesh;
//Material buffer
ID3DXBuffer *pD3DXMaterials;
//Number of materials
DWORD g_dwNumMaterials;
//Material list and texture list
D3DXMATERIAL *pMaterials;
D3DMATERIAL9 *g_pMaterialList;
IDirect3DTexture9 **g_pTextureList;
//An effect to go
ID3DXEffect* g_pEffect;
//Normal map
IDirect3DTexture9 *g_pNormal;
//Position
D3DXVECTOR4 pos;
//fx
bool fx;
//select tech result
HRESULT effect;
public:
AStaticObject();
~AStaticObject();
BOOL Load(const char *Filename, AGraphics &graphics);
BOOL LoadNM(const char *Filename, AGraphics &graphics);
BOOL Render(AGraphics &graphics);
BOOL LoadEffect(const char *Filename, AGraphics &graphics);
BOOL SetTransform(float x, float y, float z);
};
Everything works fine except for when I do anything with IDirect3DTexture9 *g_pNormal;. When I call LoadNM() it works just fine and the texture loads as follows:
BOOL AStaticObject::LoadNM(const char *Filename, AGraphics &graphics)
{
if(FAILED(D3DXCreateTextureFromFile(graphics.GetDevice(), Filename, &g_pNormal)))
return FALSE;
return TRUE;
}
which produces a texture with the normal map. The error comes when I exit the program. It says
"Unhandled exception at 0x00401770 in armageddon.exe: 0xC0000005: Access violation reading location 0x00000008."
whether I try to release the texture or not. The directx debug does not give me any information on this and I have gotten this problem before but it has always been easy to fix. Can anyone tell me what the issue may be? Thanks.