D3D device creation failed

Started by
5 comments, last by Evil Steve 16 years, 1 month ago
I am using the Nov 2007 SDK and trying to build a DirectX 9 app but the device creation code is failing. I don't remember having this problem until I installed the Nov 2007 SDK, but I am not sure if that's the problem. I upgraded my video card's driver's to the latest and installed the latest DX EURTs. Here is the code if anyone wants to take a look:

void initD3D(HWND hwnd)
{
	HRESULT hr;
	d3d = Direct3DCreate9(D3D_SDK_VERSION);
	D3DPRESENT_PARAMETERS pp;
	ZeroMemory(&pp, sizeof(pp));
	pp.Windowed = true;
	pp.EnableAutoDepthStencil = true;
	pp.AutoDepthStencilFormat = D3DFMT_D16;
	pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	pp.hDeviceWindow = hwnd;

	hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pp, &dev);
	if (FAILED(hr))
		MessageBox(NULL, L"Could not create device", L"Error", MB_OK);
}

If anyone knows what might be going on, any help will be appreciated. Thanks. -AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Advertisement
Which error is the function returning? Are you running with the DirectX debug runtimes? If so, what do they say?
As SiCrane said, the Debug Runtimes will tell you exactly what's wrong. If you're using the November 2007 SDK, there's a bug in the DirectX Control Panel where the "Enable Hardware Acceleration" has an opposite meaning - Turning it on will disable hardware acceleration (Meaning CreateDevice and GetCaps will fail if you request the HAL device), and turning it off will enable HW acceleration.
I'm not sure what error it is returning. I tested for common return values, but it isn't any of them. Is there a way to obtain a string representation of the error so I can write it to a log or something? As for the debug output, the only thing I see pertaining to the problem is:

Direct3D9: (WARN) :HW device not available. GetAdapterCaps fails.

But I used the the DirectX Caps Viewer and there doesn't seem to be any issues with my caps. Thanks.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Quote:Original post by Evil Steve
As SiCrane said, the Debug Runtimes will tell you exactly what's wrong. If you're using the November 2007 SDK, there's a bug in the DirectX Control Panel where the "Enable Hardware Acceleration" has an opposite meaning - Turning it on will disable hardware acceleration (Meaning CreateDevice and GetCaps will fail if you request the HAL device), and turning it off will enable HW acceleration.


And there you have it folks. Such an annoying bug, this problem has been plaguing me for some time now and it turns out to be something like that. Anyway, I got my program running and the world is safe once again. Thanks, Evil Steve. Btw, is this problem resolved in the March 2008 SDK?

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Quote:Original post by u235
Is there a way to obtain a string representation of the error so I can write it to a log or something?


DXGetErrorDescription()
Quote:Original post by u235
Quote:Original post by Evil Steve
As SiCrane said, the Debug Runtimes will tell you exactly what's wrong. If you're using the November 2007 SDK, there's a bug in the DirectX Control Panel where the "Enable Hardware Acceleration" has an opposite meaning - Turning it on will disable hardware acceleration (Meaning CreateDevice and GetCaps will fail if you request the HAL device), and turning it off will enable HW acceleration.


And there you have it folks. Such an annoying bug, this problem has been plaguing me for some time now and it turns out to be something like that. Anyway, I got my program running and the world is safe once again. Thanks, Evil Steve. Btw, is this problem resolved in the March 2008 SDK?
I'm not sure, I hope so [smile]

Anyone here got the Mark SDK installed and able to check?


Also, for future reference, there's a couple of ways to check the error code.
First, if you're posting it, post it as a 8 digit hex number (sprintf, etc format would be "%08x"). The first 4 digits are the success/fail bit and the module ID. The last 4 digits is the actual error code, when converted to decimal.
For example, if CreateDevice returns 0x8876086c, the first 4 digits are 0x8876 - that first 8 means "failure" (The high bit is set), the 876 part means "D3D", and the 086c part is the error code - 2156 in decimal. If you search d3d9.h for that number, you'll come across this:
#define D3DERR_INVALIDCALL MAKE_D3DHRESULT(2156)
Which obviously means the error is D3DERR_INVALIDCALL. If you can't find the error code in d3d9.h, try plugging it into the error lookup tool,; it might be a generic Win32 error like E_ACCESS or E_OUTOFMEMORY.

The other way is to use the SDK function DXGetErrorString. That'll convert the HRESULT code to a readable error message like "D3DERR_INVALIDCALL". It'll also handle Win32 error codes like "E_OUTOFMEMORY".

This topic is closed to new replies.

Advertisement