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 )
  • 相关阅读:
    MySQL crash-safe replication
    Innodb单表数据物理恢复
    从MySQL全库备份中恢复一个库和一张表
    mysqldump中master-data和dump-slave的区别
    mysqldump常用参数
    mysqldump --single-transaction 和--lock-tables参数详解
    CF757E Bash Plays with Functions
    通过binlog日志统计dml语句,找出操作频繁的表
    [SDOI2015]约数个数和
    常用binlog日志操作命令
  • 原文地址:https://www.cnblogs.com/graphics/p/1739757.html
Copyright © 2011-2022 走看看