How to Debug XNA GraphicsDevice Errors

The Problem

If you're developing an XNA application, chances are that you've seen a COM exception at least once. These exceptions aren't very talkative and usually don't help you much in locating the source of the problem:

An InvalidCallException triggered by the XNA GraphicsDevice

Typically, an InvalidCallException as shown in the screenshot above will pop up and you have to figure out if the parameters you called a method with were wrong, something is missing in the setup code (especially for the DrawPrimitive() method which relies on vertex declaration, index & vertex streams as well as shaders being set beforehand) or just some state hasn't been set correctly.

The Solution

Luckily, the Direct3D Developer Runtime provides very good feedback whenever a method call you make fails. And since XNA is built on top of Direct3D, we can benefit from that, too. To see the Direct3D feedback, you first need to install the DirectX Developer Runtime (often also referred to as the DirectX Debug Runtime). This special runtime can be found in the DXSDK\Developer Runtime directory in recent DirectX SDKs.

Earlier DirectX SDKs provided a system control panel entry to configure DirectX options, but this has now moved into the start menu. Look for the "DirectX Control Panel" entry in the DirectX SDK folder:

The DirectX Control Panel entry in the start menu

Here you can toggle between the debug and the release runtime as well as adjust the amount of debug output you want to see.

The DirectX Develope Runtime Control Panel

  • Debug - Special developer runtime that validates everything you do with a Direct3D device, thus catching errors you might not even notice if you would develop with the End-User DirectX Runtime. Whenever a method fails, in-depth error information is written to the system debug log.
  • Release - Optimizied end-user runtime which runs as fast as possible. Switch back to this if you want to play the latest games on your developer machine ;)

Activate debug messages by selecting the Debug runtime and adjusting the Debug Level slider. The slider controls what messages will be generated by Direct3D. If you leave it at the Less side, only critical errors will be reported, while on the More side, Direct3D will even tell you when you've set a RenderState to the same value it already has.

Next we need some logger that can capture the debug messages generated by Direct3D. A very good (and free!) utility for this purpose is SysInternals' DebugView:

DebugView showing some Captured DirectX Debug Messages

So next time you get an InvalidCallException that you can't see the cause of, you know what to do!

KoviRobi's picture

NoSuitableGraphicsDeviceException

Hello!
I have tried what you have done but it didn't work for me. I have got the following errormessage:

Microsoft.Xna.Framework.NoSuitableGraphicsDeviceException was unhandled
Message="Could not find a Direct3D device that has a Direct3D9-level driver and supports pixel shader 1.1 or greater."
Source="Microsoft.Xna.Framework.Game"
StackTrace:
at Microsoft.Xna.Framework.GraphicsDeviceManager.CheckForAvailableSupportedHardware()
at Microsoft.Xna.Framework.GraphicsDeviceManager.ChangeDevice(Boolean forceCreate)
at Microsoft.Xna.Framework.GraphicsDeviceManager.Microsoft.Xna.Framework.IGraphicsDeviceManager.CreateDevice()
at Microsoft.Xna.Framework.Game.Run()
at XNA_Tutorial_part1.Program.Main(String[] args) in C:\Documents and Settings\Robi\Dokumentumok\Visual Studio 2005\Projects\XNA Tutorial part1\XNA Tutorial part1\Program.cs:line 14

Thank you!

Cygon's picture

You don't need DebugView for this ;)

The DebugView trick can only help you if Direct3D is successfully initialized, which it is not in your case. The exception you've posted says it all:

Could not find a Direct3D device that has a Direct3D9-level driver and supports pixel shader 1.1 or greater.

XNA requires a graphics card with Pixel Shader 1.1 support (eg. at minimum a GeForce 4x00 TI card). Either your graphics card is too weak or you don't have a DirectX 9.0-level driver installed.

Mott's picture

Thats worse!

I got that same message (Could not find a Direct3D device that has a Direct3D9-level driver and supports pixel shader 1.1 or greater.) and i do have direct x9.0. my graphics card is Geforce 4 MX 4000. My computer isnt that old and can run games like dawn of war dark crusade which is alota more graphical then my clown on the screen with XNA. so is there nothing i can do beside pay jst to make amatuer games? if anyone know and different way to run it that would be very helpful, cause if u dont ill be stuck working on game maker 7.0.

Cygon's picture

It's possible but not recommended

Here's how to make it work:
Using the Reference Rasterizer in XNA.
I've had this explanation up for ages. Google is your friend.

However, I wouldn't even bother with the reference rasterizer unless you're using a notebook. You can get a graphics card with shader support for less than $25 - new. If you don't mind ebay, then make that $5.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <br> <a> <em> <strong> <u> <i> <b> <cite> <blockcode> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <pre> <span>
  • You can highlight code with any of the following tags: <blockcode>

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.