PDA

View Full Version : CreateDevice Error~Help


Frente
09-04-2005, 04:10 AM
I wrote these code in my program:

LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
LPDIRECT3D9 D3D = NULL;
D3D = Direct3DCreate9( D3D_SDK_VERSION);

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));

d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = 640;
d3dpp.BackBufferHeight = 480;
d3dpp.hDeviceWindow = hwnd;

long result = D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,&g_pd3dDevice);


But everytime i got result : D3DERR_INVALIDCALL~~

Could anybody help me ?
thx

bladder
09-04-2005, 10:41 AM
Are you checking that "D3D" is not NULL after you call Direct3DCreate9(D3D_SDK_VERSION)?

The values you are specifying for you d3dpp object seem fine to me.


Your program would most probably crash if D3D was NULL, so forget that.

Could you turn on the debug runtime for d3d (from the control panel), the debug your applciation. Then look in the output pane and see what Direct3D complains about.

Nick
09-04-2005, 12:05 PM
You have to specify what you want for the depth buffer. Either set d3dpp.AutoDepthBuffer to FALSE and it won't create a depth buffer for you, or set it to TRUE and also specify a valid format for d3dpp.AutoDepthStencilFormat.

Actually that can't be the problem because you zero the D3DPRESENT_PARAMETERS structure, but still, its good practice to set all fields...

Nick
09-04-2005, 12:14 PM
I tested your code, and it works fine, except when hwnd is an invalid window handle. :excl: Could you check that it's not zero or any other invalid value? How do you retrieve it?