Skip to main content
GameDev.net gamedev.net
🔒 Locked

Device Creation Failure - On Start

Started by KieranChandler Feb 15, 2012 at 3:40 AM 36 replies 5.4k views
Original Post
KieranChandler
KieranChandler
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
Evil Steve
Evil Steve
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?
KieranChandler
KieranChandler
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;
}
Evil Steve
Evil Steve
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?
Evil Steve
Evil Steve
Do you get any debug output at all? And any D3D output at all? What version of the DirectX SDK are you using?
Evil Steve
Evil Steve
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.
Washu
Washu
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.
Evil Steve
Evil Steve
Windows 7: Just type "dxdiag" in the start menu
Windows XP -> Start Menu -> Run -> "dxdiag.exe"
Windows Vista: I think the same as Windows 7.

Also, what is the value of hRet when CreateDevice() fails (Look at it in the debugger, preferably in hexadecimal view)?
KieranChandler
KieranChandler
I know where it is but I don't know what I am supposed to be doing with it. E_FAIL
Evil Steve
Evil Steve

I know where it is but I don't know what I am supposed to be doing with it.
Click Save All Information, and then paste the contents of the text file here.


E_FAIL
Really? I've never seen CreateDevice() return that, it should be something like D3DERR_INVALIDCALL or D3DERR_NOTAVAILABLE.
Evil Steve
Evil Steve

It doesn't give me the option to save it.
What happens when you click on the "Save All Information" button then?


Oh how do I check it ?

Also, what is the value of hRet when CreateDevice() fails (Look at it in the debugger, preferably in hexadecimal view)?
KieranChandler
KieranChandler
There is no save All information button. How do i get the hexadecimal view
KieranChandler
KieranChandler
I think it may be something wrong with my computer because unity won't start up, it's giving me an error saying it can't initialize Direct3D.
Evil Steve
Evil Steve
What version of the DirectX SDK do you have? Can you give us a screenshot of your dxdiag window? What version of Windows do you have? What graphics card do you have? Do you have the latest drivers?

It sounds like you don't have a D3D9 compatible video card, or you're running through remote desktop, virtual machine or something similar that would prevent D3D9 from being used.

You can get to hexadecimal view in Visual Studio by right clicking in the watch window in the debugger and selecting "Hexadecimal Display".

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.