zoukankan      html  css  js  c++  java
  • 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模式下使用

    代码
    #if defined(DEBUG) | defined(_DEBUG)
    #define DXTRACE_MSG(str) DXTrace( __FILE__, (DWORD)__LINE__, 0, str, FALSE )
    #define DXTRACE_ERR(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, FALSE )
    #define DXTRACE_ERR_MSGBOX(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, TRUE )
  • 相关阅读:
    linux基础练习题(3)
    linux基础练习题(2)
    linux基础练习题(1)
    编辑器 vim
    Linux 命令总结
    Sublime Text 3 快捷键总结(拿走)
    Linux 主要目录速查表
    javaScript中的querySelector()与querySelectorAll()的区别
    javaScript定时器
    js基本类型和字符串的具体应用
  • 原文地址:https://www.cnblogs.com/graphics/p/1739757.html
Copyright © 2011-2022 走看看