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

CreateDevice failed in DX9 under Vista [SOLVED]

Started by amarhys Aug 22, 2008 at 1:45 PM 1 replies 2.8k views
Original Post
amarhys
amarhys
Hello, I am currently working on a DX9 game engine. I started the development under XP but I changed to Vista recently. Under Vista, call to ::createDevice always fails returning D3DERR_INVALIDCALL (the same piece of code works fine under XP, I tried it on at least 3 or 4 computers). Here is the D3D initialization code :


HRESULT InitD3D (int resWidth, int resHeight, D3DFORMAT resFormat, HWND hWnd, DWORD fullScreen)
{
HRESULT hr;
D3DDISPLAYMODE d3ddm;


//---------------------------------------------
//         Create D3D object
//---------------------------------------------
d3d = Direct3DCreate9(D3D_SDK_VERSION);

// Make sure NULL pointer was not returned
if (!d3d)
  return FALSE;

//---------------------------------------------
//       Get device capabilities
//---------------------------------------------
ZeroMemory (&d3dCaps, sizeof(d3dCaps));
    
D_CHK ( d3d->GetDeviceCaps (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps) );

//---------------------------------------------
//     Setup device present parameters
//---------------------------------------------
ZeroMemory(&d3dPresent,sizeof(d3dPresent));

// WINDOWED MODE
if (fullScreen == 0)
{
        
  RECT rWindow;

  // Get display mode
  D_CHK ( d3d->GetAdapterDisplayMode (D3DADAPTER_DEFAULT, &d3ddm) );

  // Get window bounds
  GetClientRect (hWnd, &rWindow);

  // Setup backbuffer format
  d3dPresent.Windowed = true;
  d3dPresent.BackBufferFormat	= d3ddm.Format;
  d3dPresent.BackBufferWidth	= rWindow.right - rWindow.left;
  d3dPresent.BackBufferHeight	= rWindow.bottom - rWindow.top;	
}
// FULLSCREEN MODE
else
{      
  // Setup backbuffer format
  d3dPresent.Windowed = false;
  d3dPresent.BackBufferFormat = resFormat;
  d3dPresent.BackBufferWidth  = resWidth;
  d3dPresent.BackBufferHeight = resHeight;	
}

// Front / Back buffer
d3dPresent.SwapEffect		= D3DSWAPEFFECT_DISCARD; 
d3dPresent.hDeviceWindow	= hWnd;
d3dPresent.BackBufferCount	= 1;
d3dPresent.PresentationInterval	= D3DPRESENT_INTERVAL_DEFAULT;

d3dPresent.MultiSampleType	= D3DMULTISAMPLE_NONE; // No multisample
d3dPresent.MultiSampleQuality	= 0;

// Stencil buffer
d3dPresent.EnableAutoDepthStencil = TRUE;
d3dPresent.AutoDepthStencilFormat = D3DFMT_D16;

D_CHK (d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
	d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE,
        d3dPresent.AutoDepthStencilFormat));

D_CHK (d3d->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
       d3ddm.Format, d3dPresent.BackBufferFormat, 
       d3dPresent.AutoDepthStencilFormat));

// Others
d3dPresent.Flags			= 0;
d3dPresent.FullScreen_RefreshRateInHz	= 0;

//---------------------------------------------
//			 Create D3D device 
//---------------------------------------------
if (d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
{    
  // Create device with hardware vertex processing
  D_CHK ( d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hWnd,
                D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dPresent, &d3dDevice) );
}
else
{
  // Create device with software vertex processing
  D_CHK ( d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hWnd,
            D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dPresent, &d3dDevice));
}
				
//---------------------------------------------
//	 Enable dialog boxes (Windows mode only)
//---------------------------------------------
if (fullScreen==0) {
  D_CHK ( d3dDevice->SetDialogBoxMode(TRUE) );
}

return TRUE;
}



D_CHK is a simple macro to check HRESULT value and exit when it fails. My development environment : - Visual Studio C++ .NET 2003. - Microsoft DirectX SDK (June 2008) - Vista Family Premium SP1 - Video Card : ATI Mobility Radeon HD 3470 I include , and I link with d3d9.lib d3dx9.lib dxerr.lib I know that Vista includes both DX9 and DX10. Do I need to indicate to Vista I want to execute the application under DX9 ? (somewhere in the tool settings or the project configuration) If not, does anybody have an idea to explain why createDevice fails ? Thank you in advance for your answer. Cheers Amarhys [Edited by - amarhys on August 22, 2008 3:39:31 PM]
Evil Steve
Evil Steve
Are you trying to create a fullscreen device or windowed? Fullscreen has some more restrictions.

You don't seem to be checking if the backbuffer format is acceptable or if the depth buffer format is usable.
This link shows how to correctly check all these things.

Finally, what do the Debug Runtimes tell you?
amarhys
amarhys
I activated the Debug Runtimes (I was not familiar with this debug method) and I found quickly the cause of the error : hWnd pointer was NULL (I did not expected this kind of error that's why I did not check) because CreateWindowEx failed ...
Once repaired DX9 initialization works fine :-)

Thanks Evil Steve
Cheers
Amarhys

Topic Locked

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

Sign in to reply to this topic.