创建DirectX 10设备和交换链时的“E_FAIL” - _com_error

时间:2012-03-31 14:45:08

标签: c++ directx

我正在使用一些简单的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值,但似乎无效。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我尝试在VMware虚拟机中创建设备。它失败了(设备保持为NULL),直到我将请求的FEATURE_LEVEL从D3D10_FEATURE_LEVEL_10_1更改为D3D10_FEATURE_LEVEL_9_3。我听说这也可以帮助其他拥有真实硬件的电脑。