Archived

This topic is now archived and is closed to further replies.

Invalid Call?!

This topic is 5041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I''m intializing the D3D stuff in my program right now, but whenever I run it, when the D3DDevice is created, an error of invalid call always comes up. I can''t figure out what the problem is, and even reverted to using code from the first tutorial and still not meeting any success. Can anyone see if there''s anything wrong with this?
HRESULT c_GameCore::InitGraphics(HWND WindowHandle)
{
	D3DInterface = Direct3DCreate9(D3D_SDK_VERSION);
	
	MessageBox(WindowHandle, "GameCore initgraph test2", NULL, MB_OK);
	
	if(D3DInterface == NULL)
	{
		MessageBox(WindowHandle, "GameCore initgraph test3", NULL, MB_OK);
		return E_FAIL;
	}
	
	D3DPRESENT_PARAMETERS D3DPP; 
    ZeroMemory( &D3DPP, sizeof(D3DPP) );
	D3DPP.Windowed = TRUE;
    D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD;
    D3DPP.BackBufferFormat = D3DFMT_UNKNOWN;

    HRESULT hr;

	hr = D3DInterface->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, WindowHandle,
										D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                        &D3DPP, &D3DDevice);
	if(FAILED(hr))
    {
	MessageBox(WindowHandle, DXGetErrorDescription9(hr), NULL, MB_OK);
		return E_FAIL;
    }
Right at the end there is where the error occurs.

Share this post


Link to post
Share on other sites
its definetly the way you''re filling out your D3DPP variable. You need to fill out more then just the Windowed/SwapEffect/BackBuffer mebers of the structure. Check the docs, there are lots of things missing, and all of them are being set to 0 because of the ZeroMemory call.

BackBufferHeight & BackBufferWidth you definetly need to be filling, I dunno if you can get away with the PresentationInterval member though...try it out.


| TripleBuffer Software |
| Plug-in Manager :: System Information Class :: C++ Debug Kit :: DirectX Tutorials :: Awesome Books |

Share this post


Link to post
Share on other sites
Yes, you should fill out all of the members explicitly as a matter of course.

The reason why your setup is failing is because the BackBufferWidth, BackBufferHeight can only be set to 0 if you''re creating a windowed mode device. Same thing with BackBufferFormat - it can only be set to D3DFMT_UNKNOWN when creating a windowed mode device. This is all covered quite well in the SDK docs.

Since you''ve initialized the Windowed struct member variable to 0 (FALSE) from your call to ZeroMemory, you''re asking D3D to create a full-screen device.

BTW, you also aren''t creating a depth buffer when you create the device and swap chain of surfaces, so that might not be what you want. You''ll need to set EnableAutoDepthStencil and AutoDepthStencilFormat prior to calling CreateDevice.



Share this post


Link to post
Share on other sites
quote:
Original post by don
Since you''ve initialized the Windowed struct member variable to 0 (FALSE) from your call to ZeroMemory, you''re asking D3D to create a full-screen device.



He''s set his WIndowed member to TRUE. Look again.


| TripleBuffer Software |
| Plug-in Manager :: System Information Class :: C++ Debug Kit :: DirectX Tutorials :: Awesome Books |

Share this post


Link to post
Share on other sites
Yep, my mistake. Goes to show you that I shouldn''t be answering these questions before I''ve had my morning coffee.

OK, I''ve actually run his code and it succeeds on my machine. I can get it to fail with D3DERR_INVALIDCALL if I intentionally pass in a bogus window handle. So my second guess (now that I''m awake) is that the window handle is bad when the function is called.


Share this post


Link to post
Share on other sites
You might try running under the debug D3D9 runtime and looking at the messages sent to the debugger''s output window when CreateDevice fails. If it''s a bad window handle, it will tell you.

Share this post


Link to post
Share on other sites