Need help with a DX8 initialization problem

Started by
4 comments, last by flaXen 22 years, 5 months ago
I''m trying to write a library (a simple Win32 DLL) of DX8/D3D functions using VC++6 for use in a game. I want to handle all D3D stuff inside of my library. My problem is that even if I cut & paste the code from the DX8SDK (D3D tutorial #1), I can''t get D3D to initialize properly inside of the DLL, yet the tutorials compile and execute fine. I''m using VB to test the DLL, but Delphi is what the game is written in. (The DX8SDK D3D VB samples work fine too) The error occurs on the last line of the initialization where the code reads: if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice))) { return E_FAIL; } CreateDevice is returning D3DERR_INVALIDCALL. hWnd is passed into the init function from VB and is the hWnd of a PictureBox which is visible and borderless. This D3D init function isn''t getting called while the form is being created (per MS''s advice). Instead, it''s being called when I click on a button in my form. Can anyone help me? Has anyone else made DX8 initialize D3D inside of a DLL like this? Any input would be very helpful, and THANKS! -- Dan (flaXen)
Advertisement
1. Install the debug version of the D3D runtimes and bump up the D3D debug level. Then run the program and watch what gets sent to the debug output. D3D will tell you _why_ it returned INVALIDCALL in the output.

2. The window handle passed for the FOCUS window should be a *top level* window. It can''t be a child (such as a control). If you want the rendering to appear inside a control, make the DEVICE window that of the control.

3. Another reason for an INVALIDCALL error would be a problem with the presentation parameters you''ve passed. Maybe the Z buffer mode doesn''t work with the desktop mode, maybe you''ve not specified windowed mode, maybe you''ve specified a swap mode or multisample mode the device can''t do etc etc...

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

  		D3DDISPLAYMODE d3ddm;				if(FAILED(hr=m_pD3D8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))			return(hr);				switch(bFullScreen_)			{			case TRUE:				//FullScreen				m_D3DParam.Windowed         = FALSE;				m_D3DParam.SwapEffect       = D3DSWAPEFFECT_DISCARD;				m_D3DParam.BackBufferCount  = 1;				m_D3DParam.hDeviceWindow    = m_hRenderWnd;				m_D3DParam.BackBufferWidth  = 640;				m_D3DParam.BackBufferHeight = 480;				m_D3DParam.BackBufferFormat = D3DFMT_A8R8G8B8;							//ZBuffer				m_D3DParam.EnableAutoDepthStencil = TRUE;				m_D3DParam.AutoDepthStencilFormat = D3DFMT_D16;				break;						default:			case FALSE:				//Windowed				m_D3DParam.Windowed         = TRUE;				m_D3DParam.SwapEffect       = D3DSWAPEFFECT_FLIP;				m_D3DParam.BackBufferFormat = d3ddm.Format;				m_D3DParam.BackBufferCount  = 1;				m_D3DParam.hDeviceWindow    = m_hRenderWnd;				//ZBuffer				m_D3DParam.EnableAutoDepthStencil = TRUE;				m_D3DParam.AutoDepthStencilFormat = D3DFMT_D16;				break;			};  

You can try disabling the stencil/Z buffer to see if it has an effect. Or, the right way, is to call CheckDeviceFormat and ask for the D3DUSAGE_DEPTHSTENCIL properties.

You may need to call CoInitialize first as well.

Is there an easy way to flip between the debug and retail Dx8 drivers?

Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

quote:
You can try disabling the stencil/Z buffer to see if it has an effect. Or, the right way, is to call CheckDeviceFormat and ask for the D3DUSAGE_DEPTHSTENCIL properties.


Also call CheckDepthStencilMatch() on the format. CheckDeviceFormat() only checks whether the device supports surfaces in that format. CheckDepthStencilMatch() checks what will work together. Small gotcha is that CDSM() doesn''t catch all non-matches under DX8.0 (should do in 8.1). So on cards which have restrictions (i.e. nVidia cards), if you don''t turn on special driver matching ("match Z depth to frame buffer depth" in Advanced section of display settings you may get some OK returns for depth formats which will later fail.


quote:
You may need to call CoInitialize first as well.


Direct3DCreate8() should do that for you (never needed it myself).


quote:
Is there an easy way to flip between the debug and retail Dx8 drivers?


In DX8.1, there is a new option in the DirectX control panel ("Debug/Retail Runtime") which lets you switch (can''t remember if it was present in 8.0). IIRC you need to select debug runtime at installation time for it to work properly.


--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

I''ve tried passing it the window handle of both the main form and the control within the form where I wanted to display the D3D output, but both cause the same error.

Setting the debug level high was easy, but I don''t have any idea how to view debug output. Can anyone point me in the right direction?

Also, DX8.0 has the debug/retail switch in the control panel applet along with the debug level controls for each component of DX8.

Thanks for the help everyone!
You can view debug output window in the environment of your compiler (assuming the DLL was built with something like MSVC).

Alternatively you can use a standalone debug output viewer utility such as DebugView (free from www.sysinternals.com). This will let you see any output sent to the debug stream by D3D - the output will tell you the exact reason for it''s unhappiness.

What you see in the debug output will be something like:
quote:
Direct3D8: (ERROR) :BackBufferCount must be less than D3DPRESENT_BACK_BUFFERS_MAX. CreateDevice/Reset Fails.
Direct3D8: (ERROR) :Failed to initialize Framework Device. CreateDevice Failed.


(That was the output from a deliberate test case I just made where I asked for 20 back buffers, but you can see how the output is more useful than the error code alone)

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement