Skip to main content
gamedev.net
🔒 Locked

Debug DX8 questions

Started by mdfmKoRn 6 replies 450+ views
Original Post
mdfmKoRn
mdfmKoRn
In all the time I''ve ever written programs, I''ve never debugged them. Good practice, eh? Oh well, my noviceness never ends. Getting to the point: I cranked the D3D8 debug all the way up and set it to break on memory leaks. The thing runs just fine fullscreen. If I run it in a window, I get this error: Direct3D8: :====> ENTER: DLLMAIN(00cc3650): Process Detach 000007dc, tid=00000508 Direct3D8: (INFO) :MemFini! Direct3D8: (ERROR) :Memory still allocated! Alloc count = 119 Direct3D8: (ERROR) :Current Process (pid) = 000007dc I have no idea what this is trying to tell me. Could someone fill me in? Also, while the program''s running, I get message after message saying: Direct3D8: (WARN) :Ignoring redundant SetRenderState # or Direct3D8: (WARN) :Ignoring redundant SetTextureStageState Stage: #, State: # where #=a different number with each message. wtf is this saying? There''s only a few places these calls are made in my code (in fact I think SetTextureStageState is never called) and I''m pretty sure they''re not repeated without a cause. ---- Herb M. (mdfmKoRn) www.sky-meyg.com s3202@attbi.com
S1CA
S1CA
1) some memory used by an object you asked DirectX to allocate wasn''t free''d. This is usually because you forgot to Release() an object or forgot about an implicit reference. A common example is that the last SetTexture() call you made bumped the refcount for the texture - you need to SetTexture(NULL) for that stage before you Release(). Same with things like vertex buffers.

Take a careful look at all of your Release() and shutdown code to make sure all object references have been Release()d.

Also if the debug output gives you the AllocIDs of any of those objects, you could use the new Break on AllocID to get a breakpoint on the offending objects allocation.


2a) D3D is a "state" model - once you set a state to a certain value, it stays set to that state until you set it to a different value. (Or until someone else does - say when you lost a device because someone Alt-Tabbed to a different app).

2b) Because of this model, if you set a state to the value it''s already set to, then the call is pointless and wasteful. An example:
SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
SetRenderState( D3DRS_ZWRITEENABLE,FALSE );
SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );

ALPHABLENDENABLE is being set twice. This could be as a result of a state being set to the same value at the start of every frame for example.

2c) Wrapping your SetRenderState() and SetTextureStageState() calls up in some lazy evaluation code is good practice if you''re doing something big like a game engine.

2d) Internally, some D3DX calls will set states themselves, as do some graphics drivers when you call CreateDevice(). These could be what you''re seeing if you haven''t set any yourself.

2e) Largely the "Ignoring redundant XXX" warnings can be ignored unless you''re really trying to get every last drop of performance out of an engine.

2f) Its ok to get them when the program starts up, just not every frame - in fact our engine gets about 50. But there''s a good reason for that, we initialise EVERY renderstate, texture state etc to a KNOWN default value. Although D3D docs list defaults for renderstates, not all drivers set these defaults. Experience with flaky PC graphics hardware drivers will teach you to never trust the defaults and always make sure you KNOW what the states are set to.


--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
mdfmKoRn
mdfmKoRn
Thanks again, man. I found the reason for the memory leak. There was a bug in my message loop that was closing everything before deallocating anything. (bad!)

As for the redundancy, it''s not every frame, it''s mostly when the program starts. Um, but there''s one thing.... I don''t think 900 of them''s normal. Yes, 900... wtf?

What I know: I haven''t set any of the defaults, I just left them for D3D to set.

What I don''t know: I''m passing pointers to the D3DDevice to other cpp files. Could this cause the mass calls for the defaults?


----
Herb M. (mdfmKoRn)
www.sky-meyg.com
s3202@attbi.com
S1CA
S1CA
quote:

What I don''t know: I''m passing pointers to the D3DDevice to other cpp files. Could this cause the mass calls for the defaults?



the act of passing pointers in itself won''t account for them, but if what''s in those C++ files is setting states from the pointer it recieves it could do!

Try running the app in a window and drag it out of the way so that you can see the MSVC debug window (or use an external debugger). Look to see if new messages appear while the app is running - if they do, something in your code between the top of the frame and the Present() is setting renderstates. If you''re making D3DX calls during a frame it could be this.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
mdfmKoRn
mdfmKoRn
Actually, you''re on the right track, Mr. Annonymous.

I spent the last hour or so tracking down those nastly little bugs. It turns out the crash on exit was due to forgetting to Release() on of my textures.

Now, on to another issue. Big problems with this font thing. I''m using DrawText() to render my text. If I comment out the DrawText lines, the thousands of SetRenderState calls cease. Is there a way to draw text in D3D without this happening?

----
Herb M. (mdfmKoRn)
www.sky-meyg.com
s3202@attbi.com
S1CA
S1CA
They''re warnings rather than "bugs" - so they *can* be ignored - some games have shipped with actual errors ignored (hint: load an external debug viewer while running things like Max Payne )

All of the sample code which ships with the DirectX SDK is written for clarity NOT for absolute best performance! - Looking at the code for CD3DFont, it does set states during a frame without consideration for whether that state is already set. As do many of the samples!.

If they''d added a layer of lazy evaluation, it''d just complicate the code.

If you''re *really* upset about the warnings, code your own state set wrapper and redirect their calls.

For prototyping and R&D I use their stuff, but performance doesn''t bother me in that case. For released code I tend to roll my own.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
mdfmKoRn
mdfmKoRn
I'm not using CD3DFont, I'm using ID3DXFont. (not sure about how accurate that is, it's something like that, I haven't looked)

Normally I would just ignore the warnings, but there's just one complication. Any more than about 3 lines of text drops my frame rate to under 12fps. So, yeah, I'm *really* upset about the warning.

Q: I'm not sure what you mean by redirect their calls.

lol, I feel like I'm picking your brain to pieces, dude. Thanks.


----
Herb M. (mdfmKoRn)
www.sky-meyg.com
s3202@attbi.com


Edited by - mdfmKoRn on January 6, 2002 1:03:41 PM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.