2012-03-31 127 views
0

我正在通過一些簡單的DX教程工作,並且遇到了一個早期障礙。我正在使用舊筆記本電腦和新PC,因此我使用了d3d10_1.lib,它允許我使用9個功能集。但是,個人電腦確實支持DX11,所以沒有什麼問題。當創建DirectX 10設備和交換鏈時出現`E_FAIL` _com_error

因此,這裏是它失敗的功能:

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

有一個在調試輸出太行:

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值嘗試過,但似乎並沒有工作。

+0

您是否打開了DirectX控制面板中的調試輸出?它應該給你一個更有用的調試花絮。 – Puppy 2012-03-31 14:57:41

+0

對於10/11,我現在已經有了,但DirectX9選項卡上的選項全部變灰。 – Cylindric 2012-03-31 15:00:11

+0

D3D10_1_SDK_VERSION應該是D3D10_SDK_VERSION作爲功能級別9 ... – zezba9000 2012-07-26 16:50:28

回答

0

我認爲問題可能與我發送的D3D10_CREATE_DEVICE_FLAG有關。我將D3D10_CREATE_DEVICE_SINGLETHREADED | D3D10_CREATE_DEVICE_DEBUG更改爲0,現在可以使用。

0

我試圖在VMware虛擬機中創建設備。它失敗了(設備保持爲NULL),直到我將請求的FEATURE_LEVEL從D3D10_FEATURE_LEVEL_10_1更改爲D3D10_FEATURE_LEVEL_9_3。我聽說這也有助於其他具有真正硬件的PC。

相關問題