Skip to main content
GameDev.net gamedev.net
🔒 Locked

Device / Textureloading problem

Started by suckxez Jan 2, 2007 at 6:14 PM 0 replies 650+ views
Original Post
suckxez
suckxez
Hi! I'm new to DirectX and was trying to put the basic initialization stuff in some classes. So I have a gfx_core class which has a IDirect3DDevice9* pD3DDevice9 declared as private and a "IDirect3DDevice9* GetDevice()" method (public of course). Then theres a sprite and a texture class. Inside this texture class I try to load a texture as followed:

LPDIRECT3DTEXTURE9 pD3DTexture;
D3DXIMAGE_INFO SrcInfo;

D3DCOLOR colorkey = 0xFFFF00FF;

if(FAILED(D3DXCreateTextureFromFileEx(GFX->GetDevice(), "metal.png", 0, 0, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 
D3DX_FILTER_NONE, D3DX_DEFAULT, colorkey, &SrcInfo, NULL, &pD3DTexture))) {
//error handling
}




In gfx_core:

IDirect3DDevice9* GetDevice() {
return pD3DDevice9;
}




GFX is a singleton object to my mentioned gfx_core class. The program crashes with an unhandled exception because D3DXCreateTextureFromFileEx returns false. It seems to me that this GFX->GetDevice stuff doesn't work or rather IDirect3DDevice doesn't like to get passed via methods returning that deviceobject. I bet it would work if I do the textureloading inside my gfx_core class which holds the device object. I'm getting desperate.
Xrystal
Xrystal
I haven't used singleton objects in my projects but I have DXBase class which has the accessor to the projects Device which all my other classes gain access to via the Engine / Main program.

EG:
CDXBase* m_pDirectX;
m_pDirectX = new CDXBase();
... Initialisation of Base Class goes here ...
m_pFont = new CDXFont(m_pDirectX->GetDevice());
... Initialisation of Font Class goes here ...
etc:

So far I haven't had problems with functions not working due to the GetDevice not working but more because the rest of the function is missing something.

I also access that function to do other items not in programmed routines:

m_pDirectX->GetDevice()->SetRenderState(... , ....);
etc.

If the GetDevice seems faulty try assigning it temporarily to a variable to see if it really is retrieving the value you are expecting. Remembering of course to release the new variable.

One thing though, unless you do the magic with the AddRef option on the device don't release the device inside the other classes. In essence you are using the same device variable for the lifetime of the project. I only release the device in the DXBase class destructor or anywhere else in the DXBase class where the variable might have to be destroyed. It took me awhile but I managed to track down every memory leak the debug mode located and now never move on to the next coding step until I am sure that the memory leaks have been dealt with.

But I digress. Hopefully there is a more plausible explanation to your problem but hopefully I mentioned something that nudged your memory.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.