CreateDevice Fails - Why?

Started by
6 comments, last by carb 20 years, 9 months ago
I''m getting IDirect3D9::CreateDevice to fail ... It''s returning D3DERR_INVALIDCALL, but I can''t figure out why. I''ve even reduced my code to the following simple little thing, but the same problem still occurs. // begin code // error checking if (hWnd = NULL) return false; // initialize Direct3D if((m_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) return false; ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // create the Direct3D object if (m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_pD3DDevice) == D3DERR_INVALIDCALL) { printf("Fail\n"); return false; } // end code I''m wondering if not including some library or header file could screw this up - I mean, this is right out of the SDK docs. Any help would be very much appreciated. - Ben
- Ben
Advertisement
I''m an idiot. Really.

if (hWnd = NULL) return false;

Fabulous piece of code there.

- Ben
- Ben
Hahahaha.. the good ole..

.lick
Erp, I fixed that, but something''s still wrong. I mean, now it returns D3DERR_NOTAVAILABLE instead. I''m more than sure my computer supports software vertex processing and software lighting.

Any help, please?

- Ben
- Ben
Hi - I''m not sure if you can set d3dpp.backbufferformat to D3DFMT_UNKNOWN.

Try the following (in VB/DX8.1, but I''m sure you can convert it):

'' Get The current Display Mode format
Dim mode As D3DDISPLAYMODE
d3d.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
D3DPP.BackBufferFormat = mode.Format

hope this helps-

BM
According to the docs, D3DFMT_UNKNOWN defaults to the current display settings ... those lines were taken right from a tutotial.

- Ben
- Ben
first off, you were entirely correct to return false if HWND==NULL;

Also, you should tell DX what the presentation INterval is::


here is a general code for setting the PresentParameters in windowed mode, before you attempt to create a device:

ZeroMemory(&Parms,sizeof(D3DPRESENT_PARAMETERS));
Parms.Windowed=true;
Parms.BackBufferWidth=Display.Width;
Parms.BackBufferHeight=Display.Height;
Parms.SwapEffect=D3DSWAPEFFECT_DISCARD;
Parms.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;
Parms.BackBufferFormat=Display.Format;
Parms.EnableAutoDepthStencil=true;
Parms.AutoDepthStencilFormat=D3DFMT_D24S8;
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
quote:Original post by RhoneRanger
first off, you were entirely correct to return false if HWND==NULL;


Heheheh. You didn''t read that carfully.
He did: hwnd = NULL, not hwnd == NULL.

Thats why you should do: NULL == hwnd. So if you forget the other = it will cause a compile error rather than creating a difficult to track bug.



This topic is closed to new replies.

Advertisement