Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay, I'm going insane here, there seems to be absolutely nothing wrong, yet D3D10CreateDeviceAndSwapChain() keeps failing because of 'invalid' parameters (0x887A0001), even though I've searched the web and everything I find seems to confirm that my code is just fine. Someone please tell me what the function's problem is.

C++
bool CreateGraphicsObjects(void)
{
	DXGI_SWAP_CHAIN_DESC scd				= {0};

	scd.BufferDesc.Width					= AppData.Width;
	scd.BufferDesc.Height					= AppData.Height;
	scd.BufferCount							= 1;
	scd.BufferDesc.Format					= DXGI_FORMAT_R8G8B8A8_UNORM;
	scd.BufferDesc.ScanlineOrdering			= DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE;
	scd.BufferDesc.Scaling					= DXGI_MODE_SCALING_UNSPECIFIED;
	scd.BufferDesc.RefreshRate.Denominator	= 50;
	scd.BufferDesc.RefreshRate.Numerator	= 1;
	scd.SampleDesc.Count					= 1;
	scd.SampleDesc.Quality					= 0;
	scd.SwapEffect							= DXGI_SWAP_EFFECT_DISCARD;
	scd.BufferUsage							= DXGI_USAGE_RENDER_TARGET_OUTPUT;
	scd.OutputWindow						= AppData.MainWnd;
	scd.Windowed							= FALSE;

	D2D1_RENDER_TARGET_PROPERTIES rtp;

	rtp.pixelFormat.format					= DXGI_FORMAT_R8G8B8A8_UNORM;
	rtp.type								= D2D1_RENDER_TARGET_TYPE_DEFAULT;
	rtp.pixelFormat.alphaMode				= D2D1_ALPHA_MODE_PREMULTIPLIED;
	rtp.usage								= D2D1_RENDER_TARGET_USAGE_NONE;
	rtp.minLevel							= D2D1_FEATURE_LEVEL_DEFAULT;
	rtp.dpiX								= 0;
	rtp.dpiY								= 0;

	if ((Error = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_SINGLETHREADED, D3D10_SDK_VERSION, &scd, &SwapChain, &Gfx)) != S_OK)
	{
		RetCode = -1;
	}
	else if (SwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)&BkgBuff) != S_OK)
	{
		RetCode = -2;
	}
	else if (BkgBuff->QueryInterface(__uuidof(IDXGISurface), (void**)&BkgSurf) != S_OK)
	{
		RetCode = -3;
	}
	else if (D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &D2D) != S_OK)
	{
		RetCode = -4;
	}
	else if (D2D->CreateDxgiSurfaceRenderTarget(BkgSurf, &rtp, &Rtg) != S_OK)
	{
		RetCode = -5;
	}
	else if (DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory), (IUnknown**)&DWrite) != S_OK)
	{
		RetCode = -6;
	}
	else
	{
		RetCode = 0;
	}

	if (RetCode != 0)
	{
		return false;
	}

	return true;
}


What I have tried:

I've tried literally everything, read the MSDN documentation, searched for tutorials, changing parameters around, etc, it just doesn't want to work.
Posted
Updated 11-Dec-17 14:05pm
v2
Comments
Jochen Arndt 11-Dec-17 8:52am    
Check if your runtime parameters (AppData width, height, and main window handle) are valid.

You might use D3D10_CREATE_DEVICE_DEBUG to get a more detailed message about which parameters being wrong (requires installed D3D debug support).

If still not solved use the documentation to check if there is a conflict with the used parameters and the requested operations are supported by your hardware.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900