D3D11CreateDevice()返回垃圾值并失败 [英] D3D11CreateDevice() returns garbage value and fails

查看:728
本文介绍了D3D11CreateDevice()返回垃圾值并失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习《 DirectX11 3D游戏编程》这本书。

I just started studying direct 3d with the book 3D Game Programming with DirectX11.

我遵循了第一个教程,并得到一个MessageBox,上面写着 D3D11CreateDevice Failed。

I followed the first tutorial and got a MessageBox saying "D3D11CreateDevice Failed".

我检查了此函数的返回值,并得到了 -2005270483 的垃圾值。
十六进制值 0x887a002d ,人们说这是 DXGI_ERROR_SDK_COMPONENT_MISSING 错误。

I checked the return value of this function and got the garbage value of -2005270483. The hexadecimal value of 0x887a002d, which people say it's DXGI_ERROR_SDK_COMPONENT_MISSING error.

但是,我找不到有关它的任何信息。此外,MSDN通知的也不是 D3D11CreateDevice()的可能值。

However, I couldn't find any information about it. Also, it was none of the possible value of D3D11CreateDevice() that MSDN notifies.

以下是代码创建D3D设备的书:

Following is the code of the book creating the D3D device:

bool D3DApp::InitDirect3D()
{
    // Create the device and device context.

    UINT createDeviceFlags = 0;
#if defined(DEBUG) || defined(_DEBUG)  
    createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

    D3D_FEATURE_LEVEL featureLevel;
    HRESULT hr = D3D11CreateDevice(
        0,                 // default adapter
        md3dDriverType,
        0,                 // no software device
        createDeviceFlags, // createDeviceFlags, 
        0, 0,              // default feature level array
        D3D11_SDK_VERSION,
        &md3dDevice,
        &featureLevel,
        &md3dImmediateContext);

    if( FAILED(hr) )
    {
        // I added this part to check out the return value
        TCHAR str[100];
        int code = -1;

        switch(hr) {
        case D3D11_ERROR_FILE_NOT_FOUND: code=0;
            break;
        case D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS: code=1;
            break;
        case D3D11_ERROR_TOO_MANY_UNIQUE_VIEW_OBJECTS: code=2;
            break;
        case D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD: code=3;
            break;
        case DXGI_ERROR_INVALID_CALL: code=4;
            break;
        case DXGI_ERROR_WAS_STILL_DRAWING: code=5;
            break;
        case E_FAIL: code=6;
            break;
        case E_INVALIDARG: code=7;
            break;
        case E_OUTOFMEMORY: code=8;
            break;
        case E_NOTIMPL: code=9;
            break;
        case S_FALSE: code=10;
            break;
        case S_OK: code=11;
            break;
        } // switch
        _stprintf(str, L"D3D11CreateDevice Failed. Code:%ld %d", hr, code);

        MessageBox(0, str, 0, 0);
        return false;
    } // if
...

我目前正在研究Windows 8.1和DirectX版本11。
我的图形卡是NVIDIA GeForce GTX650。我使用的
编译器是VS2010 Express。

I'm currently working on Windows 8.1 with DirectX version 11. My graphics card is NVIDIA GeForce GTX 650. Compiler I use is VS2010 Express.

有人知道吗?问题和解决方案?

Does anyone knows what's the problem and solution?

推荐答案

问题是您没有为操作安装正确的DirectX调试运行时系统。 旧版DirectX SDK (2010年6月)具有适用于Windows Vista SP2和Windows 7 aka DirectX 11.0的正确DirectX调试运行时,但不适用于具有KB 2670838 aka DirectX 11.1或DirectX 11.2。

The problem is that you do not have the correct DirectX Debug Runtime installed for your operating system. The legacy DirectX SDK (June 2010) has the correct DirectX Debug Runtime for Windows Vista SP2 and Windows 7 aka DirectX 11.0, but not the correct one for Windows 8.0, Windows 8.1, or Windows 7 SP1 with KB 2670838 aka DirectX 11.1 or DirectX 11.2.

对于Windows 8.1,唯一正确安装DirectX Debug Runtime的方法是安装Windows 8.1 SDK。如果您已安装Visual Studio 2013,则此操作会自动完成,或者您可以直接在系统上安装SDK。您还可以通过安装Visual Studio 2013远程调试工具包来获取Windows 8.1 SDK调试运行时。请参见 Direct3D SDK调试层技巧

For Windows 8.1, the only way to get the proper DirectX Debug Runtime installed is to install the Windows 8.1 SDK. This is done automatically if you had installed Visual Studio 2013, or you can install the SDK directly on your system. You can also get the Windows 8.1 SDK debug runtime by installing the Visual Studio 2013 Remote Debugging Tools packages. See Direct3D SDK Debug Layer Tricks for a complete table of matching up debug runtimes with SDKs.

请注意,独立安装Windows 8.1 SDK并继续使用旧版DirectX SDK就足够了(六月2010)和VS 2010一起获得 D3D11_CREATE_DEVICE_DEBUG 以便在Windows 8.1上再次运行,但是我建议(a)升级到VS 2012或VS 2013-或-(b)使用道具解决方案,用于将Windows 8.1 SDK与VS 2010集成在一起,以获取最新版本的标题。 DirectX工具包就是为了获得VS 2010支持。

Note that it would be sufficient to install the Windows 8.1 SDK standalone and continue to use the legacy DirectX SDK (June 2010) with VS 2010 to get D3D11_CREATE_DEVICE_DEBUG to work again on Windows 8.1, but I would recommend either (a) upgrading to VS 2012 or VS 2013 -or- (b) using the 'props' solution to integrate the Windows 8.1 SDK with VS 2010 for the latest versions of the headers. The DirectX Tool Kit does this for VS 2010 support.

如果您需要在VS 2010项目中继续使用仅旧版DirectX SDK组件(如D3DX11),则可以将Windows 8.1 SDK与DirectX SDK结合使用,但请确保列出DirectX SDK的include和lib路径<在Windows 8.1 SDK包含和lib路径之后(参见 MSDN

If you need to continue to use legacy DirectX SDK only components like D3DX11 as well for your VS 2010 project, then you can combine the Windows 8.1 SDK with the DirectX SDK but be sure to list the DirectX SDK include and lib paths after the Windows 8.1 SDK include and lib paths (see MSDN).

总结:理想的解决方案是仅在Windows 8.1上使用Visual Studio 2013,而根本不使用旧版DirectX SDK 。 Win32桌面Direct3D教程Windows Store应用程序Direct3D教程的构建完全不需要传统的DirectX SDK。许多DirectX SDK示例现已在 MSDN代码上提供使用Windows 8.x SDK构建且不使用旧版DirectX SDK的Gallery

To sum up: the ideal solution is to just use Visual Studio 2013 on Windows 8.1 without the legacy DirectX SDK at all. The Win32 desktop Direct3D tutorial or the Windows Store app Direct3D tutorial builds just fine without the legacy DirectX SDK at all. Many of the DirectX SDK samples are available now on MSDN Code Gallery that build with the Windows 8.x SDK and do not make use of the legacy DirectX SDK.

解决当前问题的最小方法是安装 Windows 8.1 SDK 或Visual Studio 2013远程调试工具(x86 x64 )以获取正确的版本为您的操作系统安装的SDKDebugLayers中的内容,但请记住,Frank Luna的书现在过时了。有关其他说明,请参见图书推荐

The minimal solution to your immediate issue is to just install the Windows 8.1 SDK or the Visual Studio 2013 Remote Debugging Tools (x86 or x64)to get the correct version of the SDKDebugLayers installed for your operating system, but keep in mind that Frank Luna's book is rather dated now. See Book Recommendations for some additional notes.

这篇关于D3D11CreateDevice()返回垃圾值并失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆