Error Checking in DX

简介:

from http://nexe.gamedev.net/directKnowledge/default.asp?p=Debugging

When you're trying to find out why a specific function is failing - and the debug output isn't helping - you need to work with return codes. Note, however, that you should always check error codes, not just when debug output isn't useful. More or less all the functions in the DirectX API return HRESULT?s, the standard COM return type. Given an HRESULT? hr, you can check for success and failure using the following macros:
- SUCCEEDED(hr) will be true if hr indicates an 'ok', that is, the function you got the result from succeeded. We stress here that you should never compare an HRESULT? to S_OK or whatever to check for success, because success can be indicated by many values, not just S_OK.
- FAILED(hr) will be true if hr indicates a failure.
Additionally, the following functions and macros are helpful as well:
- DXGetErrorString9(hr) will return a string which is the name of the constant that hr represents. If hr were D3DERR_DEVICELOST, the string would be "D3DERR_DEVICELOST".
- DXGetErrorDescription9(hr) will return a string which describes the error code in hr. If hr were D3DERR_DEVICELOST, the string would be something like "The device has been lost but cannot be reset at this time. Therefore, rendering is not possible".
- DXTRACE_ERR("function�failed:�",�hr) will output - to the debug view - the current source file, line number, the string "function failed: " and the string produced by DXGetErrorString9(hr)
- DXTRACE_ERR_MSGBOX("function�failed:�",�hr) does exactly the same thing as DXTRACE_ERR, except that it pops up a dialog box with the error, as well as printing it to the debug output.
- DXTRACE_MSG("hello") is the same as writing DXTRACE_ERR("hello",�0). (It doesn't use hr at all but we're including it for completeness).
You can also feed the error code to the DirectX Error Lookup tool in the DirectX SDK to get a description.
When you're working with DirectX types in the debugger, you will probably find it useful to read In|Framez's article on auto-expand information for DirectX9. It'll make the debugger a lot more 'intelligent' when working with DirectX.

all the Macros above were can be found in DxErr.h

an example about this, the following code show the error message on a box

 
 
const WCHAR * errorString = DXGetErrorString(hr) ;
DXTRACE_ERR_MSGBOX(errorString, hr) ;

注意有些函数只能在DEBUG模式下使用

 

ContractedBlock.gif 代码

 本文转自zdd博客园博客,原文链接:http://www.cnblogs.com/graphics/archive/2010/05/20/1739757.html,如需转载请自行联系原作者

相关文章
error C2041: illegal digit ‘9‘ for base ‘8‘ | error C2059: syntax error: ‘bad suffix on number‘
error C2041: illegal digit ‘9‘ for base ‘8‘ | error C2059: syntax error: ‘bad suffix on number‘
133 0
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179)
327 0
|
Unix Linux 异构计算
成功解决 ERROR: An error occurred while performing the step: “Building kernel modules“. See /var/log/nv
成功解决 ERROR: An error occurred while performing the step: “Building kernel modules“. See /var/log/nv
成功解决 ERROR: An error occurred while performing the step: “Building kernel modules“. See  /var/log/nv
error: possibly undefined macro: AC_PROG_LIBTOOL
error: possibly undefined macro: AC_PROG_LIBTOOL
299 0
Dx unsupported class file version 52.0 Conversion to Dalvik format failed with error 1
Dx unsupported class file version 52.0 Conversion to Dalvik format failed with error 1
146 0
error: x264_bit_depth undeclared (first use in this function) did you mean x264_picture_t
error: x264_bit_depth undeclared (first use in this function) did you mean x264_picture_t
153 0
libs/spandsp/src/floating_fudge.h:40:20: error: implicit declaration of function ‘sin’ [-Werror=impl
libs/spandsp/src/floating_fudge.h:40:20: error: implicit declaration of function ‘sin’ [-Werror=impl
111 0
ERROR: libx264 not found
ERROR: libx264 not found
158 0
|
Perl
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1
682 0
Dx unsupported class file v
Dx unsupported class file v
114 0