0

我正在尝试从 IDXGIAdapter 创建设备和交换链。我的所有代码都会成功,直到调用返回 DXGI_ERROR_INVALID_CALL 的 CreateSwapChain。

MSDN 说,当 DXGI_SWAP_CHAIN_DESC 为空或 IDXGISwapChain** 为空时,可能会返回 DXGI_ERROR_INVALID_CALL。

我不太确定“IDXGISwapChain ** 为空”是什么意思,因为它是输出(我猜是当你实际输入 NULL 时。

我的交换链被定义为...

IDXGISwapChain* m_pSwapChain;

我的其他代码是...

IDXGIAdapter * pPrimaryAdapter = m_vAdapters.at(0); 

HRESULT hr = D3D10CreateDevice(pPrimaryAdapter,
                                D3D10_DRIVER_TYPE_HARDWARE,
                                NULL,
                                NULL,//D3D10_CREATE_DEVICE_SINGLETHREADED
                                D3D10_SDK_VERSION,
                                &m_pD3DDevice);


if(hr != S_OK)
{
    MessageBox(NULL, L"Error ###: Creation of Direct3D10 Device Failed", 0, 0);
    return false;
}

//m_pDXGIFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER ); 
if(FAILED(m_pDXGIFactory->MakeWindowAssociation(hWnd, 0 )))
{
    MessageBox(0, L"Error ###: MakeWindowAssociation Failed", 0,0);
    return false;
}

IDXGIDevice * pDXGIDevice;
if(FAILED(m_pD3DDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice)))
{
    MessageBox(0, L"QueryInterface pDXGIDevice Failed", 0,0);
    return false;
}




DXGI_SWAP_CHAIN_DESC SwapChainDesc;

    SwapChainDesc.BufferCount = 1;
    SwapChainDesc.BufferDesc.Width = 800;
    SwapChainDesc.BufferDesc.Height = 600;
    SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    SwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
    SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
    SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    SwapChainDesc.OutputWindow = hWnd;
    SwapChainDesc.SampleDesc.Count = 1;
    SwapChainDesc.SampleDesc.Quality = 0;
    SwapChainDesc.Windowed = TRUE;



hr = m_pDXGIFactory->CreateSwapChain(pDXGIDevice, &SwapChainDesc, &m_pSwapChain);

switch(hr)
{
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
    {
        MessageBox(NULL, L"CreateSwapChainFailure: DXGI_ERROR_NOT_CURRENTLY_AVAILABLE", 0,0);
        return false;
    }break;
case DXGI_ERROR_INVALID_CALL:
    {
        MessageBox(NULL, L"CreateSwapChainFailure: DXGI_ERROR_INVALID_CALL", 0, 0);
        return false;
    }break;

};
4

1 回答 1

0

您是否尝试过SwapChainDesc在分配值之前将内存归零?您没有指定结构的所有值,因此除非将其归零,否则某些参数可能无效。

尝试:

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

SwapChainDesc.BufferCount = 1;
....
于 2012-12-21T05:48:59.100 回答