【问题标题】:`E_FAIL` when creating DirectX 10 Device and Swap Chain - _com_error创建 DirectX 10 设备和交换链时出现“E_FAIL” - _com_error
【发布时间】:2014-03-23 05:29:30
【问题描述】:

我正在学习一些简单的 DX 教程,但遇到了早期的障碍。我正在使用旧笔记本电脑和新 PC,所以我使用 d3d10_1.lib,它可以让我使用 9 个功能集。但是,PC 确实支持到 DX11,所以那里应该没有问题。

所以这是失败的函数:

bool DirectX9Renderer::Initialise(HWND* handle)
{
    //window handle
    hWnd = handle;

    //get window dimensions
    RECT rc;
    GetClientRect( *hWnd, &rc );
    UINT width = rc.right - rc.left;
    UINT height = rc.bottom - rc.top;

    DXGI_SWAP_CHAIN_DESC swapChainDesc;
    ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));

    //set buffer dimensions and format
    swapChainDesc.BufferCount = 2;
    swapChainDesc.BufferDesc.Width = width;
    swapChainDesc.BufferDesc.Height = height;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;;

    //set refresh rate
    swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
    swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;

    //sampling settings
    swapChainDesc.SampleDesc.Quality = 0;
    swapChainDesc.SampleDesc.Count = 1;

    //output window handle
    swapChainDesc.OutputWindow = *hWnd;
    swapChainDesc.Windowed = true;    

    HRESULT result = D3D10CreateDeviceAndSwapChain1( // this is line 57
        NULL, 
        D3D10_DRIVER_TYPE_HARDWARE,
        NULL, 
        D3D10_CREATE_DEVICE_SINGLETHREADED | D3D10_CREATE_DEVICE_DEBUG,
        D3D10_FEATURE_LEVEL_9_1,
        D3D10_1_SDK_VERSION,
        &swapChainDesc, 
        &pSwapChain,
        &pD3DDevice
    );
    if(FAILED(result))
    {
        return FatalError("D3D device creation failed");
    }

            // there's more stuff after this, but I don't get that far
    }

因此,对D3D10CreateDeviceAndSwapChain1 的调用失败,错误代码E_FAIL 帮助不大。

Debug 输出中也有一行:

First-chance exception at 0x770f56c4 in TileTest.exe: Microsoft C++ exception: _com_error at memory location 0x00b6e8d4..

我尝试过使用 D3D10_DRIVER_TYPE_REFERENCE 和不同的 D3D10_FEATURE_LEVEL_xx 值,但它似乎不起作用。

【问题讨论】:

  • 您是否在 DirectX 控制面板中打开了调试输出?它应该给你一个更有用的调试喷射。
  • 我现在有,10/11,但 DirectX9 选项卡上的选项都是灰色的。
  • D3D10_1_SDK_VERSION 应该是 D3D10_SDK_VERSION 作为功能级别 9...
  • 该类名为 DirectX9Renderer 但您创建的是 D3D10 设备? ;-)

标签: c++ directx


【解决方案1】:

我认为问题可能与我发送的D3D10_CREATE_DEVICE_FLAG 有关。我将D3D10_CREATE_DEVICE_SINGLETHREADED | D3D10_CREATE_DEVICE_DEBUG 更改为0,现在它可以工作了。

【讨论】:

    【解决方案2】:

    我尝试在 VMware 虚拟机中创建设备。在我将请求的 FEATURE_LEVEL 从 D3D10_FEATURE_LEVEL_10_1 更改为 D3D10_FEATURE_LEVEL_9_3 之前,它失败了(设备保持 NULL)。我听说这也有助于其他具有真实硬件的 PC。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-01
      • 1970-01-01
      相关资源
      最近更新 更多