CreateSwapChain failed

Started by
16 comments, last by Neilo 12 years, 8 months ago
I recently started working with Direct3D 11, but I am having some problems with initializing it.

The code below failes on the last line. It returns the following hr: -2005270527.
I have tried to use GetLastError and then use HRESULT_FROM_WIN32, and I get the following error: "The specified module could not be found."

I know I can use D3D11CreateDeviceAndSwapChain, but I need the IDXGIFactory to disable ALT-ENTER.

Can someone please tell me what is wrong with the following code.
It worked with Direct3D 10 and the only difference is D3D11CreateDevice instead of D3D10CreateDevice.


D3D11CreateDevice(0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, 0, 0, D3D11_SDK_VERSION, &Device, 0, &DevCon);

CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&Factory);

DXGI_SWAP_CHAIN_DESC SwapChainDesc;
ZeroMemory(&SwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
SwapChainDesc.BufferDesc.Width = 800;
SwapChainDesc.BufferDesc.Height = 600;
SwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
SwapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
SwapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
SwapChainDesc.SampleDesc.Count = 1;
SwapChainDesc.SampleDesc.Quality = 0;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.BufferCount = 1;
SwapChainDesc.OutputWindow = Window->hWnd;
SwapChainDesc.Windowed = true;
SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
SwapChainDesc.Flags = 0;

Factory->CreateSwapChain(Device, &SwapChainDesc, &SwapChain);
TGUI, a C++ GUI for SFML
texus.me
Advertisement
I could be wrong but the RefreshRate variable looks wrong to me. Should probably be set like this instead (for 60hz)

SwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
Thanks for the reply, but this did not solve the problem.
TGUI, a C++ GUI for SFML
texus.me

I recently started working with Direct3D 11, but I am having some problems with initializing it.

The code below failes on the last line. It returns the following hr: -2005270527.

That return code should correspond to one of these DirectX return codes, which should at least help to better define and narrow down the problem.

That return code should correspond to one of these DirectX return codes.

I did found some return codes here that I was not comparing my hr with, but none of the return codes equals to my hr.

I finally found out what the hr is by using DXTrace. The error is DXGI_ERROR_INVALID_CALL.
I went to the msdn site and there I found that I would get this error when pDesc or ppSwapChain is NULL.

My SwapChain is NULL when calling the function, but isn't this supposed to be?
TGUI, a C++ GUI for SFML
texus.me
Hmm. I'm not sure. How do you declare [font="Lucida Console"]SwapChain[/font]?

How do you declare SwapChain?
[/quote]

IDXGISwapChain SwapChain;
SwapChain = NULL;

I already tried to don't make it NULL, but it has the same result.

I did however find a way to make my code work by replacing CreateDXGIFactory with:

IDXGIDevice* pDXGIDevice;
Device->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice);

IDXGIAdapter* pDXGIAdapter;
pDXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void **)&pDXGIAdapter);

pDXGIAdapter->GetParent(__uuidof(IDXGIFactory), (void **)&Factory);

Do I really need to do it this way or is there a way to just use CreateDXGIFactory?
TGUI, a C++ GUI for SFML
texus.me
This is my function for creating the device and swap chain:


void D3DSysClass::CreateDeviceAndSwapChain()
{
HRESULT hr = S_OK;

UINT createDeviceFlags = 0;

#ifdef D3DDEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );

D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );

DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 1;
sd.BufferDesc.Width = pWindow->GetWidth();
sd.BufferDesc.Height = pWindow->GetHeight();
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_UNORDERED_ACCESS;
sd.OutputWindow = pWindow->GetHWnd();
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;

for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
{
MessageBox(NULL, L"D3D11CreateDeviceAndSwapChain() failed in D3DSysClass()", L"Error", MB_OK);
exit(0);
}
}


Hope that helps.
http://msdn.microsoft.com/en-us/library/bb174537%28v=vs.85%29.aspx

IDXGIFactory::CreateSwapChain takes **ppSwapChain as it's param, you're passing it *ppSwapChain.

Try this instead:IDXGISwapChain *SwapChain = NULL;
.
.
.

Factory->CreateSwapChain(Device, &SwapChainDesc, &SwapChain);


See the difference?

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


IDXGIFactory::CreateSwapChain takes **ppSwapChain as it's param, you're passing it *ppSwapChain.

I am sorry, it is my post that is wrong, it should have been: [color="#660066"]IDXGISwapChain* [color="#660066"]SwapChain[color="#666600"];

forsandifs: In normal situations I do something like that too, but as far as I know I need a IDXGIFactory to disable ALT-ENTER.

I will just continue working like I discribed in my last post. It makes my code a bit longer, but at least it works.

I want to thank all of you for your help.
TGUI, a C++ GUI for SFML
texus.me

This topic is closed to new replies.

Advertisement