Jump to content
  • Advertisement
Sign in to follow this  
RandomGuy

"Hooking" a DirectX 9 Device

This topic is 3859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello :). I have a small question. I have one class, which holds a IDirect3DDevice9* device, which is fully initialized. Then another class needs this device to do some texture loading. Before, I had the device pointer in the function parameters which worked fine. But now I tried to istead store the device pointer in the texture loading classes private space, then on the class creation I just did this. DirectXImageLoader(IDirect3DDevice9* D3DDevice) { mDevice = D3DDevice; } And now it wont work. D3DXCreateTextureFromFile just returns IUNKOWN. Is this just a fact, or I doing something else wrong? Thaks a lot for even reading this far :D.

Share this post


Link to post
Share on other sites
Advertisement
There is nothing wrong with storing a local copy of the device object. Have you tried breaking at the call to D3DXCreateTextureFromFile and making sure that the device pointer (and everything else) is valid? If it isn't, make sure the correct constructor is being invoked.

Now I know nothing about the defined lifespans of your classes, but you can help to prevent bugs by taking advantage of reference counting. Something like this:

DirectXImageLoader::DirectXImageLoader(IDirect3DDevice9* D3DDevice) :
mDevice(D3DDevice)
{
mDevice->AddRef();
}

DirectXImageLoader::~DirectXImageLoader()
{
mDevice->Release();
}


This way, the DirectXImageLoader class won't be left with a dangling pointer if the D3D device is destroyed prematurely. I also took the device assignment inside the initialiser list, where it belongs.

Admiral

Share this post


Link to post
Share on other sites
Thanks a lot. I'll try that too then :). Most importantly, I now know that my problem most probably lies elsewhere.

[Edited by - RandomGuy on October 31, 2007 5:22:53 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!