DX8 Init Failure. Why?

Started by
6 comments, last by wcmike 21 years, 5 months ago
I can''t seem to get DX8 initalized correctly. I get an error when I try to create the DX8 device. I don''t know why, can anyone help? d3d_object, d3d_device, and hwnd are global variables. Here is the code for the function. HRESULT InitD3D() { d3d_object=Direct3DCreate8(D3D_SDK_VERSION); if(d3d_object==NULL) return E_FAIL; HRESULT hresult=d3d_object->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF,D3DFMT_X8R8G8B8,D3DFMT_X8R8G8B8,false); if(hresult!=D3D_OK) { MessageBox(hwnd,"Program error! Terminating","!",MB_OK); return E_FAIL; } D3DPRESENT_PARAMETERS d3dpresentparams; ZeroMemory(&d3dpresentparams,sizeof(D3DPRESENT_PARAMETERS)); d3dpresentparams.Windowed=false; d3dpresentparams.BackBufferCount=1; d3dpresentparams.BackBufferWidth=800; d3dpresentparams.BackBufferHeight=600; d3dpresentparams.BackBufferFormat=D3DFMT_X8R8G8B8; d3dpresentparams.SwapEffect=D3DSWAPEFFECT_DISCARD; d3dpresentparams.hDeviceWindow=hwnd; hresult=d3d_object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpresentparams,&d3d_device); if(FAILED(hresult)){ MessageBox(hwnd,"d3ddevice failed","d''oh",MB_OK); return E_FAIL; } else return D3D_OK; } Like I said, the call of d3d_object->CreateDevice() Fails. I know my computer can handle those settings because an example from my book uses it, and the program runs fine. Thank you for any help you can provide.
Advertisement
what''s the return value of the CreateDevice()? Did you ever think to check that and compare it to possible values in the DirectX docs?
CreateDevice() indeed returns a HRESULT, which is exactly what I want it to do, so that is not the problem. Thanks anyways.

Anyone else see a problem in the code?
quote:Original post by wcmike
CreateDevice() indeed returns a HRESULT, which is exactly what I want it to do, so that is not the problem.

return value tells you what the problem is. as does the debug runtime which you should be using.
The return value is INVALIDCALL, since nothing seems to work, I copied the starting application from my book and it works fine. I don''t know why it didn''t work when I typed it out myself. Thanks for the help anyway.
What they were trying to accomplish was teaching you how to find the problems yourself, rather than having us fix your code. Checking your errors and using the debug runtime would have solved your error, and then you wouldn''t have had all this hassle.

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
It sounds like you''ve never really programmed before or at least don''t understand some fundamentals. Just because a function returns a value and u assign it to something means nothing. In fact, you don''t even have to get the HRESULT value for the return. It''s only there in this case to give you your status of the call. But you would want to use it to find what''s wrong.

So your method returns D3DERR_INVALIDCALL. That means that one of your parameters or your PRESENT_PARAMS structure isn''t filled in correctly. From just looking at it and assuming that you typed it right from the book (you did type it all out right?), then perhaps either the hwnd is invalid or it has something to do with the presentation interval.

And without seeing the rest of the code, I will make a guess that it''s the window handle. It might not be of course so you''ll have to check yourself. But seeing as how you didn''t understand what the return value thing was for, I also doubt that you have the window handle being used correctly. You are probably trying to initialize Direct3D before you even get a valid window handle.
quote:Original post by Draigan
So your method returns D3DERR_INVALIDCALL. That means that one of your parameters or your PRESENT_PARAMS structure isn''t filled in correctly.

it can mean any number of things, which is why you should be using the debug runtime to find out what the problem exactly is.
quote:
From just looking at it and assuming that you typed it right from the book (you did type it all out right?), then perhaps either the hwnd is invalid or it has something to do with the presentation interval.

the whole point of the debug runtime is that you don''t need to make such guesses, but only need to read what dx tells you.
quote:
And without seeing the rest of the code, I will make a guess that it''s the window handle. It might not be of course so you''ll have to check yourself. But seeing as how you didn''t understand what the return value thing was for, I also doubt that you have the window handle being used correctly. You are probably trying to initialize Direct3D before you even get a valid window handle.

isn''t it amazing how many guesses can be solved with one line in debug output obtained from the debug runtime?

please use the debug runtime to make life easier for yourself. did i mention that the debug runtime will help you find your bugs faster?

This topic is closed to new replies.

Advertisement