Archived

This topic is now archived and is closed to further replies.

SpreeTree

D3DXCreateTextureFromResource(...)

Recommended Posts

Hi Im using D3DXCreateTextureFromResource to create a texture, and its all good. The texture loads and draws, but then when I shut down, its memory leak-tastic. I am calling Release on the D3DTexture, and setting it to NULL (just in case), but I seem to be getting win32/MFC mem leaks still. The application is being created in MFC, in case that is the problem? Anyone had this problem before, and if so, how did you solve it? Thanks

Share this post


Link to post
Share on other sites
Are you doing any AddRef()'s after the texture is loaded? If you are, make sure you're performing a Release() for every AddRef() - otherwise, the object's not getting released (its reference count is just being decreased).

Oh, and:

quote:
I seem to be getting win32/MFC mem leaks still


What's indicating that these leaks are happening? Makes it sound like it's a leak from GDI/resources and not DirectX - is that the case? I wouldn't think a D3DXCreateTextureFromResource would lock something in a resource where it was unable to release it properly ... ?


[edited by - chdennis on August 9, 2003 11:56:35 AM]

Share this post


Link to post
Share on other sites
No, Im not doing any AddRef calls. I just create the texture once, and thats it.

Its definalty not DirectX mem leaks, as if I comment out the Release() call, then the debug output on shutdown displays :

Direct3D9: (ERROR) :Memory still allocated! Alloc count = 108

Whereas these memory leaks are standard mem leak outputs :

Detected memory leaks!
Dumping objects ->
{162} normal block at 0x01185400, 4212 bytes long.
Data: < iU > 88 69 55 00 16 00 00 00 01 00 00 00 01 00 00 00
Etc...

I did initally think it was MAKEINTRESOURCE(IDB_BITMAP), but if I add that call on its own, then there are no extra memory leaks. The memory leaks only occur if D3DXCreateTextureFromResource(...) succeeds. The leaks also occur if I use D3DXCreateTextureFromFile(...).

Share this post


Link to post
Share on other sites
Ive figured out what the problem is, but its just as baffeling!

I override new and delete in _DEBUG mode, using the code example from NeHe (I think thats where its from anyway :$), but it seems that D3DXCreateTextureFromResource(...) calls the overloaded delete operator just fine, but not the overloaded new operator, so when it comes to delete the memory, it doesnt recognise it, so doesnt delete it!

Now this might be a long shot, but has anybody used this function with overloaded opertaors? Im just wondering if the new operator isnt working (as it seems to work just fine in ALL other places), or does the funtion use MALLOC/delete pairs, and as such, messes me up?

Starnge...

Cheers

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hello world,
I m using D3DXCreateTextureFromResource too but it''s doesn''t work...
can I have your function D3DXCreateTextureFromResource source code ?? please
dank

Share this post


Link to post
Share on other sites
You can get memory related errors if I don''t set the texture to NULL after releaseing it.

// Instance Texture
IDirect3DTexture9* m_Texture = NULL;

// ... Load and use it ...

// Release it
if( m_Texture != NULL )
{
m_Texture->Release();
m_Texture = NULL;
}

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
hello world,
I m using D3DXCreateTextureFromResource too but it''s doesn''t work...
can I have your function D3DXCreateTextureFromResource source code ?? please
dank


Wow I posted this topic months ago!

Why is the function not working, what is it actually doing?

Spree

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

I need your help please !! I have seek D3DXCreateTextureFromResource() in the MSDN but it say that I must load my texture( a jpg texture) with RT_RCDATA (??)
what is that ?? how can I use it ?
can you give me your source-code function who you use D3DXCreateTextureFromResource() with a jpg texture please ?

Share this post


Link to post
Share on other sites
In your resource file, you should declare your JPG resource something like:

ID_WHATEVER RCDATA DISCARDABLE "whatever.jpg"

Then, in your code, you can load it like:

D3DXCreateTextureFromResource(pDevice, NULL, MAKEINTRESOURCE(ID_WHATEVER), &m_pTexture);

xyzzy

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you are fantastic :d ! it''s perfect.
thanks
can you tell me if I can play song (always with directX) using resource ?

Share this post


Link to post
Share on other sites