Please support our sponsor:
Welcome To DirectX 4 VB! Multimedia Visual Basic at its best...

DirectX: Debugging
By: Jack Hoxley
Written: June 2000

Download: DX_Err.Zip (14.5kb)

Debugging is an important part of making an application; I hope I dont have to explain that to you...

Debugging in DirectX is even more important than any normal application; when you get an error in DirectX you can quite easily lock up an end users computer - which is not good news. Debugging is fairly easy, but there are two major obstacles:

  1. The error messages; I'd like to meet someone who knows what the error messages from directX are straight off with no translation; "-222088494 Automation Error" is all you'll get. No matter how good you are you're unlikely to ever understand that - and there's little point in trying.
  2. When you're using Fullscreen DirectDraw/Direct3D; you can't see what the error message is; you cant pause your program and you cant stop it. This can be extremely annoying, but with a little ingenuity it's actually quite easy to sort out:

The Solutions:

Part 1

There are two ways of checking what the error message is; through code or through my class module that I made especially to help you out. The DirectX library has a list of constants for all the possible error codes, you can access them through the object browser - press F2 whilst in the VB IDE (not runt time).

You can use these constants to check what the error is; but it's a bit hit and miss as you have to know what sort of errors to expect from a call. This is all well and fine if you have the SDK help file; it'll tell you this stuff. Otherwise the only method is like this:

Select case Err.Number
'It was this error
'It was this error
'......and so on..........

End Select

This is all fine if you know what DDERR_BLTFASTCANTCLIP means; but unless you have the SDK help file then you wont be able to find out.

The second; and better way of retrieving error messages is by downloading my class library. When you look at it you will find it is 1234 lines of select case. Nasty. It has an individual function for each DirectX component; which you can query as to what the error was. You can download this fom the top of this page; or from my downloads page.

'Create an instance of the class; it must be present in the project though.
Dim DXErr as New clsDX7Err

'This is the procedure you're checking:
On Error Goto ErrOut:
Exit Sub
Dim Exact as string, Desc as string
Desc = DxErr.RetDirectDrawErrorDesc(Err.Number, Exact)
msgbox "{" & Exact & "}" & vbCr & Desc
'There; you now have a more useful error dialog....

I advise that you remove this library from your project before a final compile - it'll increase the size of your EXE file and probably slow it down as well; it is only designed for development; not for use as a runtime component.

Part 2

How to debug fullscreen mode. You'll have noticed that VB just pauses your programs execution; and you're left with either a blank screen, or whatever was last rendered. The easiest way out of this is to press F1 - it'll force VB to load the help file - which will make windows minimise your broken program. You wont be able to recover again, but at least you can now see what it's trying to tell you; or if not you can try and work it out. Ignore the help file; it often brings up loads of junk that's not actually relevent to your problem.

If the error message has disappeared, just press F5 to run your application and it'll instantly stop and show you the same error message - and you can see what it's on about, and click Debug for it to show you where the error is.

There are two exceptions to this rule; 1) when using Breakpoints, 2) when there isn't actually an error.
Whe using break points everything will just freeze - the only way to get back to the code window is to press F1 and launch the help system. If there isn't actually an error; for example, you're stuck in an infinite loop and you want out - press CTRL + BREAK and it'll pause your application - you can either hit F1 to enter help or press ALT+R then press E and it'll end your application (keyboard shortcut for the Run menu-End).

Easy really; but it'll probably save you an awful lot of time. I strongly advise getting the class module listed above.

DirectX 4 VB 2000 Jack Hoxley. All rights reserved.
Reproduction of this site and it's contents, in whole or in part, is prohibited,
except where explicitly stated otherwise.
Design by Mateo
Contact Webmaster
This site is hosted by Exhedra Solutions, Inc., the parent company of and