Untitled

posted in DruinkJournal
Published December 18, 2007
Advertisement
Another one of my "I'll link to this entry from threads topic". This one's on using the debug DirectX runtimes.

The debug runtimes are debug DLLs that can be used instead of the normal D3D DLLs. They're turned on or off through a sperate utility rather than by linking to different libraries or anything.
To tun them on, go to the DirectX Control Panel, which is in Start Menu -> Programs -> DirectX SDK -> Utilities -> DirectX Control Panel, or if you're using an old SDK, it's in the Windows control panel.

You should see something like this:
DirectX Control Panel
You want to make sure that "Use Debug Version of Direct3D 9" is selected. If the option is greyed out, then you probably have an out of date SDK (So the runtimes are a differernt version to the SDK). Try downloading the latest DirectX SDK.

In debug builds (With the debug runtimes or not), you should also link to d3dx9d.lib instead of d3dx9.lib if you use D3DX. These libraries do more error checking than the standard version, so it's handy to always link to them in debug builds. My main D3D CPP file usually looks like:
#ifdef _DEBUG#   pragma comment(lib, "d3dx9d.lib")#else#   pragma comment(lib, "d3dx9.lib")#endif#pragma comment(lib, "d3d9.lib")


From sirrob:
Under Managed Projects, you need to select "Enable unmanaged debugging" in the Debug section of the project properties. If you're running C# Express 2005, you cannot view the debug output using VS, and would need to use an external tool to catch debug output (like sysinternals' dbgview).

When the debug runtimes are on, you get useful information spewed out in the debug output window of your IDE. Visual Studio 2005 shows the following:
Visual Studio 2005 Debug Output Window
(Click to enlarge)

As you can see, you get the following in the debug output:
Quote:Direct3D9: (ERROR) :Invalid iAdapter parameter. ValidateCreateDevice failed.
D3D9 Helper: IDirect3D9::CreateDevice failed: D3DERR_INVALIDCALL
Which tells you the function that failed, the reason for failure, and the error code returned (Shown in the debug watch window in the screenshot).
That makes it far far easier to find problems than trudging through with the debugger, looking for the function you forgot to check the return value of.


There's a couple of other things the debug runtimes do. First, they'll do more parameter validation than the release runtimes, so some functions may work fine on the release runtimes, but fail on the debug runtimes. This is a problem with your code, not Direct3D. It just so happens that your drivers are being leniant. One example of this is DrawIndexedPrimitive(). On NVidia cards, the drivers used to ignore the NumVertices parameter (I'm not sure if they still do), which can be used as a performance optimisation (The card only needs to transform the vertices used in a call, not all of them). So if you enter a bogus number for this parameter, it'll work on the release runtimes if the driver doesn't mind, but it'll fail on the debug runtimes because they check the parameters. The bug is in your code (It wouldn't work on an ATI card for instance), the debug runtimes are just highlighting it.
Secondly, the debug runtimes will fill some resources with debug values. The most obvious one is the backbuffer if you use D3DSWAPEFFECT_DISCARD. When you use D3DSWAPEFFECT_DISCARD, you're telling D3D that after every Present(), the backbuffer can be thrown away, and you will not be relying on it containing anything useful, which allows the drivers to do some performance optimisations. A lot of drivers don't do anything special here and behave in a similar way to D3DSWAPEFFECT_FLIP, meaning that the backbuffer contains what it did on the last frame. However, since that's not guaranteed, D3D will fill the backbuffer with magenta or green (Alternating each frame). So if you try to use the backbuffer when it's not in a valid state, you'll get a green or magenta screen. You can see this if you try to render a scene without Clear()ing the backbuffer.

EDIT 16/Feb/2008: Removed gibberish about d3d9d.lib
Previous Entry Untitled
0 likes 8 comments

Comments

sirob
Just two things I noticed were missing:

- Linking against d3dx9d.lib instead of the regular one when running the debug runtimes (or when not).

- Under Managed Projects, you need to select "Enable unmanaged debugging" in the Debug section of the project properties. If you're running C# Express 2005, you cannot view the debug output using VS, and would need to use an external tool to catch debug output (like sysinternals' dbgview).
December 18, 2007 04:32 PM
Evil Steve
Ah, good point about d3d9.lib, I've added that to my post. I've never done managed stuff, so I don't know anything about that stuff. Also added.
December 19, 2007 03:41 AM
MJP
Hey Steve,

There is no debug version of the d3d9 import library. At least, not in my SDK. [smile]
February 14, 2008 08:05 PM
Evil Steve
Quote:Original post by MJP
Hey Steve,

There is no debug version of the d3d9 import library. At least, not in my SDK. [smile]
True. There's a debug version of the D3DX library though (d3dx9d.lib). Did I say d3d9d.lib somewhere? I probably typo'd [smile]

EDIT: Err, yup, I did. Fixed it now.
February 15, 2008 03:58 PM
ankhd
no you neaver fixed it, still say d3d9d.dll
February 25, 2008 11:17 PM
Evil Steve
Quote:Original post by ankhd
no you neaver fixed it, still say d3d9d.dll
I fixed the d3d9d.dll reference, but I missed the d3d9d.lib reference. It's fixed now anyway.
March 17, 2008 11:46 AM
s_madoo
I am sory
I start create game . I want modify game have animation(".x") and have background(".bmp").but I modify have Errr line "device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);".
What error code cause?
you help Edit bug
Please Help me again

look url:
http://www.gamedev.net/community/forums/topic.asp?topic_id=502479
July 29, 2008 09:34 PM
Evil Steve
December 03, 2008 08:14 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement