Jump to content

  • Log In with Google      Sign In   
  • Create Account

Device Creation Failure - On Start


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
37 replies to this topic

#1 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 14 February 2012 - 09:40 PM

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

Sponsor:

#2 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 15 February 2012 - 04:10 AM

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?

Steve Macpherson
Systems Programmer

Rockstar North


#3 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 15 February 2012 - 06:37 AM

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;
}


#4 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 15 February 2012 - 07:20 AM

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?

Steve Macpherson
Systems Programmer

Rockstar North


#5 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 15 February 2012 - 09:04 AM

I tried that and didn't do anything :S

#6 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 15 February 2012 - 09:59 AM

Do you get any debug output at all? And any D3D output at all? What version of the DirectX SDK are you using?

Steve Macpherson
Systems Programmer

Rockstar North


#7 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 15 February 2012 - 10:22 AM

The June 2010 version

#8 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 15 February 2012 - 11:38 AM

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.

Steve Macpherson
Systems Programmer

Rockstar North


#9 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 15 February 2012 - 05:32 PM

No, it doesn't still work

#10 Washu   Senior Moderators   -  Reputation: 5240

Like
0Likes
Like

Posted 15 February 2012 - 05:35 PM

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.
ScapeCode - Blog | SlimDX


#11 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 15 February 2012 - 07:55 PM

What should I be looking for in this program ?

#12 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 16 February 2012 - 04:00 AM

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)?

Steve Macpherson
Systems Programmer

Rockstar North


#13 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 16 February 2012 - 06:00 AM

I know where it is but I don't know what I am supposed to be doing with it. E_FAIL

#14 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 16 February 2012 - 06:27 AM

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.

Steve Macpherson
Systems Programmer

Rockstar North


#15 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 16 February 2012 - 07:08 AM

It doesn't give me the option to save it. Oh how do I check it ?

#16 Adam_42   Crossbones+   -  Reputation: 2512

Like
0Likes
Like

Posted 16 February 2012 - 07:50 AM



#17 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 16 February 2012 - 08:05 AM

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)?


Steve Macpherson
Systems Programmer

Rockstar North


#18 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 16 February 2012 - 09:52 AM

There is no save All information button. How do i get the hexadecimal view

#19 KieranChandler   Members   -  Reputation: 140

Like
0Likes
Like

Posted 16 February 2012 - 10:44 AM

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.

#20 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 16 February 2012 - 11:03 AM

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".

Steve Macpherson
Systems Programmer

Rockstar North





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS