Sign in to follow this  

Resetting the device causes app slowdown

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

Hi all, I seem to be having a bit of a problem with my rendering code. It's just a simple 2D tile engine. When I toggle between fullscreen and windowed, I call OnLostDevice() for all of my objects (which releases vertex buffers, resets fonts, sprites, etc), call IDirect3DDevice9::Reset(), then call OnReset() for all my objects. All that code takes 15ms to run. Then, I set all my renderstates to what they were before the reset. I set every renderstate (210 of them or something). This usually takes 100ms or so, which is fine. However, about half the time, setting all 210 renderstates takes 6.5 seconds, causing the app to freeze for a moment. After this, my entire app goes slowly (about 10FPS when it was doing over 1000FPS before), and VC 2003 doesn't update (as if it's frozen). So, I can't tell if there's any D3D debug output. When I exit my app, VC 2003 is still frozen. I've added some logging, and my application definitely exits, and the D3D device singleton has its destructor called. At this point all of the D3D resources have been released (to the best of my knowledge). Has anyone had any problems like this before? I'm using VC 2003, DX9 (October edition - I'm downloading the Feb. SDK now), Windows 2000 with a dual monitor setup (could this be a problem? I create the device on the default adapter). Thanks for any replies, Steve

Share this post


Link to post
Share on other sites
1) Use IDirect3DDevice9::EvictManagedResources() before you Reset().

2) When releasing your D3DPOOL_DEFAULT resources, release them in the exact reverse of the order you created them in.

3) Make sure all of the members of the D3DPRESENT_PARAMETERS you pass to Reset() are what you think they are; calls like CreateDevice() can trash members of the D3DPRESENT_PARAMETERS you pass to them, so recycling the same structure (such as having it in your "device" class) can sometimes do unexpected things!

4) When first creating your resources, create *ALL* D3DPOOL_DEFAULT resources *BEFORE* your D3DPOOL_MANAGED ones.

5) Any profiling (including shutdown/Reset time) should only be done with the Retail runtimes, and only once all errors have gone with the Debug runtime and all warnings are explained.

6) You'll probably find the shutdown time is much quicker to exit on Windows XP

Share this post


Link to post
Share on other sites
I'd given up on this being answered, the topic must have been on page 3, thanks [smile]

1) I've added that line now. It doesn't seem to make any difference, but I assume it just saves the device doing it in the Reset() call.

2) Yeah, I do that as far as possible. There's a few cases where it'll be a bit of a bother to get the order right(Out of about 20 objects, 2 or 3 of them will probably be released in the wrong order), but I suppose I could do it with 30 mins - 1 hour of code changes. Do you think it's worth it?

3) Checked. The only value I rely on being persistant is the backbuffer width and height. And I've checked and double checked that it's not changing.

4) As with 2, there are a few cases where it'd be a pain to get this done right. For enabling this and #2, say 1 hour - 1h 30 mins of coding. Again, do you reckon it's worth it?

5) True, I didn't think about that. I just leave the debug runtimes on all the time. I switched to the release D3D runtime, and now it doesn't freeze for 6 seconds just after the Reset(), but the app still goes slowly (~10FPS), and VC still hangs when it exits.

6) Both my PC and my server (other test machine) are Win2k unfortunately.

I tried my code on my server, and it seems to work fine, no slowdown, no hanging at exit. Could this be a problem with my SDK installation do you think? I've got the February SDK downloaded, but I'm afraid to install it just now in case I break something further :P (And I don't like the idea of D3DX being in a DLL).

EDIT: It seems that VC freezes at some point after the device is reset (or during), since I can't break into the app once it's reset (if it's doing the long wait thing).

Thanks for the reply,
Steve

Share this post


Link to post
Share on other sites

This topic is 4667 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this