Skip to main content
GameDev.net gamedev.net
🔒 Locked

Device won't Create?

Started by Super Llama Aug 29, 2008 at 11:24 AM 13 replies 1.4k views
Original Post
Super Llama
Super Llama
I'm trying to build a simple Direct3D application with C++. I've made countless D3D programs in other languages before, specifially VB.NET and C#. This is my first C++ program, and for some reason, the Device won't initialize no matter what I do, even when I copy the code out of a tutorial (which I KNOW works.) Here's the presentation parameters (sorry for the excessive commentation but I love ASCII art :P):

//=====SETUP THE PRESENTATION PARAMETERS FOR THE DEVICE===========//------------------
//==________=====================================/*|*/ ==_____====//
//==VARIABLE=====================================/*|*/ ==VALUE====//------------------------------------
	l_D3Dpp.BackBufferCount=                     /*|*/ 1;         // The number of Back Buffers.     
	l_D3Dpp.BackBufferWidth=                     /*|*/ pWidth;    // The horizantal resolution.       
	l_D3Dpp.BackBufferHeight=                    /*|*/ pHeight;   // The vertical resolution.          
	l_D3Dpp.BackBufferFormat=                      D3DFMT_UNKNOWN;// Backbuffer format.          
	l_D3Dpp.Windowed=                            /*|*/ pWin;      // If false, the game runs fullscreen.
	l_D3Dpp.SwapEffect=                   D3DSWAPEFFECT_DISCARD;; // D3DSWAPEFFECT              
	l_D3Dpp.AutoDepthStencilFormat=              /*|*/ D3DFMT_D16;// The only format that works! ^_^   
	l_D3Dpp.EnableAutoDepthStencil=              /*|*/ true;      // Turn on the Z (depth) Buffer.    
	l_D3Dpp.hDeviceWindow=                       /*|*/ hWnd;      // Choose the device handle.       
//==CREATE DEVICE================================/*|*/============//------------------------------------

And here's the code for creating the device:

	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &l_D3Dpp, &g_pDDev ) ) )
	{
		return false;
	}

Do you see anything wrong with this? Another thing that COULD be causing the problem is this: I made a class called Graphics_Handler, containing the variables and code for creating a device. Then I made another class called a Viewport, which contains a reference to the Graphics_Handler and manages it a little better. Both classes are contained in separate header files, and the Viewport is created in the main CPP file. Is there a problem with this system? Any suggestions would be GREATLY appreciated. Thanks. [smile]
It's a sofa! It's a camel! No! It's Super Llama!
SiCrane
SiCrane
Did you run the program using the DirectX debug runtimes? If so, what did it say? Did you try using the return value from CreateDevice() in DXGetErrorDescription() to see what the failure was?
Super Llama
Super Llama
I thought the return value for the CreateDevice was only an HRESULT... it returned E_FAIL, and the program didn't continue. I'm using the DX9 SDK, but I'm not sure how to setup the debug runtimes...
It's a sofa! It's a camel! No! It's Super Llama!
Super Llama
Super Llama
Ok I checked the return value and it turned out that it wssn't E_FAIL, it was -2005530516. I'm not really sure what that code means but I'll google it. Thanks for suggesting return values :)

EDIT: I just googled it and... NOTHING came up! :S
It's a sofa! It's a camel! No! It's Super Llama!
SiCrane
SiCrane
If you read the documentation for the CreateDevice() function, you'll see that it can return one of D3DERR_DEVICELOST, D3DERR_INVALIDCALL, D3DERR_NOTAVAILABLE or D3DERR_OUTOFVIDEOMEMORY. If you take the return value and put it into the DXGetErrorDescription() function that I already mentioned it will turn the HRESULT into something that is human readable.
Super Llama
Super Llama
Wonderful! I didn't know about that function lol

I'll try it.

What header is that in?
It's a sofa! It's a camel! No! It's Super Llama!
Super Llama
Super Llama
Lol thanks, right before you posted that I remembered about google hehe

I'll try that.
It's a sofa! It's a camel! No! It's Super Llama!
Dave Hunt
Dave Hunt
There's also the DX Error Lookup tool that comes with the DirectX SDK. It should be on your Start menu under DirectX Software Developer's Kit/Tools or something like that.
VizOne
VizOne
Quote:
Original post by Super Llama
Here's the presentation parameters (sorry for the excessive commentation but I love ASCII art :P):

*** Source Snippet containing heaps of C and C++ style comments Removed ***

Sorry for being off-topic, but I have to ask: you don't "decorate" all your code like this, do you?

We've all seen "coder's art", here's an example of "artist's code" ;-)
Super Llama
Super Llama
Lol no, I don't decorate ALL code, just that header lol. Normally, I don't comment at all.

[Edited by - Super Llama on August 29, 2008 9:23:11 PM]
It's a sofa! It's a camel! No! It's Super Llama!
Super Llama
Super Llama
Update:
It returned a D3D_INVALIDCALL error. Am I giving it bad present parameters? It cant be my video card because it works in VB.NET...

What does D3D_INVALIDCALL usually mean?

(sorry for double-post btw)
It's a sofa! It's a camel! No! It's Super Llama!
Dave Hunt
Dave Hunt
Have you initialized all the members of your presentation parameters structure? If not, then some of the fields probably have garbage in them.
Evil Steve
Evil Steve
Quote:
Original post by Super Llama
Update:
It returned a D3D_INVALIDCALL error. Am I giving it bad present parameters? It cant be my video card because it works in VB.NET...

What does D3D_INVALIDCALL usually mean?

(sorry for double-post btw)
Usually something like you can't create a 32-bit backbuffer with a 16-bit depth buffer, or something like that. What do the Debug Runtimes say it means in this case? Did you try the setup code in the link Jack linked to?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.