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 )
  • 相关阅读:
    shell学习之杂项
    boot小知识
    记一个数组的问题
    lnmp安装exif扩展
    国内的Git比GitHub快
    重用思想,要有识别出好代码的眼睛,识别出腐朽代码的眼睛
    CSS3之超出隐藏
    如何测量设计图中图片的尺寸,像素
    Linux 软链接操作项目
    微信小程序申请。很蛋疼的流程。
  • 原文地址:https://www.cnblogs.com/graphics/p/1739757.html
Copyright © 2011-2022 走看看