Device Creation Failure - On Start

Started by
36 comments, last by KieranChandler 12 years, 1 month ago
Hi,
I am doing the DirectX programming course part 2 with the Game Institute. I have had many problems with finding the solutions to these errors, but this one is nowhere to be found. i have gone over the code and it matches the course project but still, when I run my game engine it runs aground instantly. It brings up an error saying "Device creation failed. The application will exit". This error message occurs when the "CreateDisplay" function shown below fails.


HRESULT D3DInitialize::CreateDisplay(CD3DSettings& Settings, ULONG Flags, HWND hWnd, WNDPROC wndProc, LPCTSTR Title, ULONG Width, ULONG Height, LPVOID lParam)
{
ULONG CreateFlags = 0;
CD3DSettings::Settings *pSettings = Settings.GetSettings();
if(!hWnd)
{
WNDCLASS wc;
wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = wndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = (HINSTANCE)GetModuleHandle(NULL);
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = Title;
ULONG Left = CW_USEDEFAULT, Top = CW_USEDEFAULT;
ULONG Style = WS_OVERLAPPEDWINDOW;
if(!Settings.Windowed)
{
Left = 0; Top = 0;
Width = pSettings->DisplayMode.Width;
Height = pSettings->DisplayMode.Height;
Style = WS_VISIBLE | WS_POPUP;
}
mhWnd = CreateWindow(Title, Title, Style, Left, Top, Width, Height, NULL, NULL, wc.hInstance, lParam);
if(!mhWnd)
return E_FAIL;
} else
{
mhWnd = hWnd;
if(!Settings.Windowed)
{
SetMenu(mhWnd, NULL);
SetWindowLong(mhWnd, GWL_STYLE, WS_VISIBLE | WS_POPUP);
SetWindowPos(mhWnd, NULL, 0, 0, pSettings->DisplayMode.Width, pSettings->DisplayMode.Height, SWP_NOZORDER);
} else
{
RECT rc;
GetWindowRect(hWnd, &rc);
SetWindowLong(mhWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);
SetWindowPos(hWnd, HWND_NOTOPMOST, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), SWP_NOACTIVATE | SWP_SHOWWINDOW);
}
}
D3DPRESENT_PARAMETERS d3dpp = BuildPresentParameters(Settings);
CreateFlags = Flags;
if(pSettings->VertexProcessingType == PURE_HARDWARE_VP)
CreateFlags |= D3DCREATE_PUREDEVICE | D3DCREATE_HARDWARE_VERTEXPROCESSING;
else if(pSettings->VertexProcessingType == HARDWARE_VP)
CreateFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
else if(pSettings->VertexProcessingType == MIXED_VP)
CreateFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
else if(pSettings->VertexProcessingType == SOFTWARE_VP)
CreateFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
mD3DDevice = NULL;
HRESULT hRet = mD3D->CreateDevice(pSettings->AdapterOrdinal, pSettings->DeviceType, mhWnd, CreateFlags, &d3dpp, &mD3DDevice);
if(FAILED(hRet))
{
if(mD3DDevice)
mD3DDevice->Release();
mD3DDevice = NULL;
return hRet;
}
return S_OK;
}


Any help will be appreciated. Thanks in advance :)


Kieran
Advertisement
Presumably CreateDevice() is failing - is that what your debugger tells you (If you put a breakpoint in the if(FAILED(hRet)) block, is it hit)?

What to the debug Direct3D runtimes tell you (Start menu -> DirectX SDK -> Tools -> DirectX Control Panel -> Direct3D9 tab, select "Use Debug Version of Direct3D 9")?

What does BuildPresentParameters() do?
Thanks, how do I use the debug runtimes ? Here is the source code for the "BuildPresentParamaters" function:


D3DPRESENT_PARAMETERS D3DInitialize::BuildPresentParameters(CD3DSettings& Settings, ULONG Flags)
{
D3DPRESENT_PARAMETERS d3dpp;
CD3DSettings::Settings *pSettings = Settings.GetSettings();
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = pSettings->BackBufferFormat;
d3dpp.Windowed = Settings.Windowed;
d3dpp.MultiSampleType = pSettings->MultisampleType;
d3dpp.MultiSampleQuality = pSettings->MultisampleQuality;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = pSettings->DepthStencilFormat;
d3dpp.PresentationInterval = pSettings->PresentInterval;
d3dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL | Flags;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
if(!d3dpp.Windowed)
{
d3dpp.FullScreen_RefreshRateInHz = pSettings->DisplayMode.RefreshRate;
d3dpp.BackBufferWidth = pSettings->DisplayMode.Width;
d3dpp.BackBufferHeight = pSettings->DisplayMode.Height;
}
return d3dpp;
}
Once you have the debug runtimes selected, you'll get D3D warnings and errors emitted to Visual Studio's output window.

What are the values of all those settings? Are you sure you've chosen settings that your graphics card supports?
I tried that and didn't do anything :S
Do you get any debug output at all? And any D3D output at all? What version of the DirectX SDK are you using?
The June 2010 version
Does it work with the following settings:
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8
d3dpp.Windowed = TRUE;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
d3dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

?
If so, then one of the values in pSettings is incompatible with your graphics card.
No, it doesn't still work
Run DXDIAG, find out what your card supports.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

This topic is closed to new replies.

Advertisement