Jump to content
  • Advertisement
Sign in to follow this  
KieranChandler

Device Creation Failure - On Start

This topic is 2483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!