Jump to content
  • Advertisement
Sign in to follow this  
NVergunst

DirectX Exceptions when window is resized or closed

This topic is 3787 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

When I resize my window, everytime, I get an error in the Sprite.Draw() function when I try to draw my texture. I am sure it is because the device is reset, but I am not sure how to prevent this. I am not using any vertecies or anything like that. Only sprites and textures. I found this thread here: http://www.gamedev.net/community/forums/topic.asp?topic_id=395483 which is exactly my problem. From the second post, there are 3 options. From my understanding #2 is bad, and #3 is a huge pain. I am loading hundreds of textures of each time from png files, actually more like 1200 and there can theoretically be an infinate number of textures loaded. Each texture has its own Sprite contained in its own class. When the device is reset, using #3, I would have to reload all the thousands of images and textures and recreate all these classes and everything. This could take a long time, and isnt good. I havent even tried it, but if I get no help and am desperate, then I will try it. So how are you supposed to handle resizing events? And I am using C# with Managed DirectX I suppose. Also when I use the TextureLoader.FromFile, there is a "pool" field that I currently have "Pool.Default". In that same thread I linked to above, it suggests using "Pool.Managed". However when I set it to managed, I get an error with error code of "2005530516" and error string of "D3DERR_INVALIDCALL" which seems rather vague... Here is the whole loading code: try { ImageInformation _ImageInfo = TextureLoader.ImageInformationFromFile(path); Texture _Texture = TextureLoader.FromFile(device, path, _ImageInfo.Width, _ImageInfo.Height, _ImageInfo.MipLevels, Usage.Dynamic, _ImageInfo.Format, Pool.Managed, Filter.None, Filter.None, 0); return new MDX_TextureLoadingReturnClass(_Texture, _ImageInfo); } catch (Exception e) { return new MDX_TextureLoadingReturnClass(); }

Share this post


Link to post
Share on other sites
Advertisement
You can't have both "Usage.Dynamic" and "Pool.Managed" at the same time. That's why you have an error when using "Pool.Managed".

If your textures are not going to be changed (I mean locked and modified) then set the Usage parameter to 0 and use "Pool.Managed"

That should solve your problem I think. Now, go read the DirectX documentation about D3DUsage and D3DPool to fully understand what is going on :)

Share this post


Link to post
Share on other sites
will do thankyou.

Any ideas as to the exception on close? It is odd, because I have set a breakpoint at the form closing and form closed events, and both register, no errors, so then I stepped it through to the end, it goes through an if statement that checks if all components are disposed (auto written code, using VS2005), then exits out to the Application.Run() command in the main loop no problems, and then exits the main loop no errors, and as it seems it is all gone, I then get the exception. When I look at the details, it says the stack includes Texture.Finalize() I believe. Unfortunately I do not know how to trap this error because it happens outside of the programmable part of my program. Any ideas?

Share this post


Link to post
Share on other sites
Any DirectX resource created in the default pool (which is your case) needs to be released before the device is resized and recreated after. If not, then DirectX can't reset its device, and throw an error. With unmanaged DirectX, you've got a message on the debug output if I remember well.

From the documentation : "When a device is lost, the application is responsible for releasing all Direct3D objects that do not survive (such as objects created in default (D3DPOOL_DEFAULT) memory"

When you resize your app, this is what happens.

Share this post


Link to post
Share on other sites
Thanks again. I realized that after reading the documentation on the pools, and was able to fix that by using the Managed tag, and now they are automatically done for me on resize.

The only thing stopping me now, is the error on exiting the application. It is such a vague error, and outside of where I can catch it, but inside enough to where VS2005 breaks in debug mode (but doesnt highlight any line of code anywhere)...

Share this post


Link to post
Share on other sites
Do you release your resources before destroying the Device and exiting ??
I don't know how the Managed framework is done, but in an unmanaged DirectX project, you have a function / method like "OnDestroyDevice()"
And in this method, you should destroy all the resources you previously loaded. For example :

void OnDestroyDevice(void)
{
// Texture is a value IDirect3DBaseTexture9 * or any
// other D3D resource that was initialized.
Texture->Release();
}

Share this post


Link to post
Share on other sites
I am capturing the form closed event, and in there I am looping through every class with a texture and calling "theTexture.Dispose()" which seems like the managed equivalent of that C++.

But I have been reading that managed actually does that for you. And with or without that code, the program runs great over and over and over except for erroring on close. I figure if I was not releasing it correctly, after quite a few restarts, the video device would return a "I'm full" exception. But doesnt matter with or without the ".Dispose()" code, it never fills up, so I am guessing it does it for you. But I still have the code in for good measure. Thanks for the idea, but I am afraid it isnt the problem. Or at least, I dont think it is. I dont know enough about DX/MDX yet to make an absolute decision. :)

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!