[mdx] dynamic texture and pool.default woes

Started by
3 comments, last by gharen2 17 years ago
I'm generating a procedural texture by writing raw pixel data to a texture with LockRectangle and UnlockRectangle. In order to do this, you need a texture created with the usage flag Dynamic, which also requires that you create it with Pool.Default. I realise that I need to dispose Pool.Default resources prior to resetting the device. And that's exactly what I do: I dispose the texture, reset the device, and recreate the texture. But there's a peculiarity that's making me pull my hair out: So long as I create the texture but don't actually use the texture, it works fine. The texture disposes, the device resets, the texture is recreated, and everyone is happy. But after I use the texture to render a sprite (with the Sprite class), the texture won't dispose any more. Instead, when I try to reset the device I get the dreaded "All user created D3DPOOL_DEFAULT surfaces must be freed before Reset can succeed. Reset Fails." error. I've tried disposing the spite class both before and after the texture. I've also set Device.IsUsingEventHandlers to false. Whatever I do, that infernal texture just won't go away, preventing me from resetting the device. Hopefully this is enough info. The code is part of a complex engine so it'd take a bit of work for me to provide a concise code sample. I will if necessary though. edit- interestingly, when I set Device.IsUsingEventHandlers to true, the application hangs while disposing the the texture, with not debug info provided by directx. [Edited by - gharen2 on April 10, 2007 2:26:07 AM]
Advertisement
Try calling OLostDevice on the Sprite interface before resetting and calling OnResetDevice after resetting. Chances are the Sprite interface isn't releasing its reference to the texture.
Sirob Yes.» - status: Work-O-Rama.
Unfortunately, that didn't work.

I think I must be overlooking a particularly obnoxious bug, because I tried to recreate the error with a simple test case, but the test case works perfectly.

I'll investigate some more.
Just a random guess, but maybe you're fetching a surface from the texture somewhere (for drawing dimensions/locking) which you forgot to dispose? Also, are you sure that the texture/surfacelevel is unlocked before you use it anywhere else? Probably a bit obvious too, but accidentally drawing a texture that is still locked is a sure way to get into trouble.

Hope this is of some help. The D3D debug runtimes also might be able to provide you with some information on which resource hasn't been disposed, but I've found getting the exact MDX resource from that info is an art beyond my skills :)
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Quote:Original post by remigius
Just a random guess, but maybe you're fetching a surface from the texture somewhere (for drawing dimensions/locking) which you forgot to dispose?


Bingo :)

I was retrieving surface 0 to get the texture's dimensions, and wasn't disposing it. In hind sight, a silly mistake considering I already knew you had to dispose of the surface you get from SwapChain.GetBackBuffer.

Funny how the simplest bugs are the most annoying :P

Thanks for your help guys. Now to clean up all the ugly hacks I put in while trying to fix the bug.

[Edited by - gharen2 on April 10, 2007 12:16:11 PM]

This topic is closed to new replies.

Advertisement