Microsoft DirectX 8.1 (Visual Basic) |
This topic lists common categories of problems that you might encounter when writing Microsoft® Direct3D® applications, and how to prevent them.
If your application fails during device creation, check for the following common errors.
Applications that use lit vertices, analogous to the D3DLVERTEX type, should disable the Microsoft® Direct3D® lighting engine by setting the D3DRS_LIGHTING render state to 0. By default, when lighting is enabled, the system sets the color for any vertex that doesn't contain a normal vector to 0 (black), even if the input vertex contained a nonzero color value. Because lit-vertices such as D3DLVERTEX don't, by their nature, contain a vertex normal, any color information passed to Direct3D is lost during rendering if the lighting engine is enabled.
Obviously, vertex color is important to any application that performs its own lighting. To prevent the system from imposing the default values, make sure you set D3DRS_LIGHTING to 0.
If your application runs but nothing is visible, check for the following common errors.
Debugging a Microsoft® Direct3D® application can be challenging. Try the following techniques, in addition to checking all the return values—a particularly important piece of advice in Direct3D programming, which is dependent on very different hardware implementations.
The second and third options in this list can help you avoid the Win16 lock which can otherwise cause your debugger to hang.
Also, try adding the following entries to Win.ini.
[Direct3D] debug=3 [DirectDraw] debug=3
Compilers from Borland report floating-point exceptions in a manner that is incompatible with Microsoft® Direct3D®. To solve this problem, include a _matherr exception handler like the following:
// Borland floating point initialization #include <math.h> #include <float.h> void initfp(void) { // Disable floating point exceptions. _control87(MCW_EM,MCW_EM); } int _matherr(struct _exception *e) { e; // Dummy reference to catch the warning. return 1; // Error has been handled. }
For performance reasons, the debug version of the Microsoft® Direct3D® Immediate Mode run time performs more parameter validation than the retail version, which sometimes performs no validation at all. This enables applications to perform robust debugging with the slower debug run-time component before using the faster retail version for performance tuning and final release.
If your application encounters unexplained failures when running with the retail Direct3D Immediate Mode run-time file, test against the debug version and look closely for cases where your application passes invalid parameters.