Sign in to follow this  
Drats

Create D3D device error

Recommended Posts

Hi, I am getting a runtime error when attempting to create the D3D device. The piece of code is m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, CreateFlags, &d3dpp, m_pD3DDevice ); m_pD3D is the Direct 3D object. The handle to the window m_hWnd comes as being 'unused' whatever that means. I have created another project with the same code and everything works fine. Could anyone suggest what the runtime error might be about.

Share this post


Link to post
Share on other sites
You can check with IsWindow(m_hwnd) prior to the call. I assume you check the validity of the window handle when you create it prior to creating the device.

Post the actual text of the error message rather than just a description. There should be an error code involved somewhere.

Share this post


Link to post
Share on other sites
What is the exact error message?

What do the debug runtimes tell you?

Have you stepped through the program with the debugger and made sure nothing funny is going on?

Do you do proper error checking (e.g., checking if CreateWindow(Ex) returns NULL)?

Share this post


Link to post
Share on other sites
I checked with IsWindow(m_hwnd) prior to the call and it turned up okay so I presume the handle to the window is alright. The error message that comes up is

First-chance exception at 0x0042781d in Game Engine.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x0042781d in Game Engine.exe: 0xC0000005: Access violation reading location 0x00000000.

Share this post


Link to post
Share on other sites
Looks like you are dereferencing a NULL pointer. Maybe m_pD3D is NULL?

Also, are you using the debug runtimes?

Finally, I will repeat my recommendation to use the debugger. You might see something you didn't expect (like a pointer being NULL when it shouldn't be).

Share this post


Link to post
Share on other sites
Mandatory linkage.

You need to be checking the return values of all of your important functions, where "important" means any function that returns data that you then rely on. That means functions like CreateDevive(), CreateVertexBuffer(), D3DXCreateTextureFromFile(), GetCaps(), etc.

If you don't check the return code, and the function fails, you're extremely likely to get a crash, or your code just not working (I.e. nothing being rendered) on some hardware.

Share this post


Link to post
Share on other sites
Oops sorry it is "&m_pDevice" in the actual program. My bad.

Could you tell me how do I use the debugger? Is there like a a guide on the net that could perhaps tell me?

Thanks.

Share this post


Link to post
Share on other sites
Quote:
it is "&m_pDevice" in the actual program

Uh.. you do realize people are taking the time to try to help you, right?

Rather than posting "I have a problem and my code looks something like this. What's wrong?" - post your actual code. Solutions will definitely come faster.

BTW, where did the info that the window is "unused" come from? That may be significant also.

Share this post


Link to post
Share on other sites
@Buckeye...I am sorry. I appreciate all of you guys helping me. I should have been more careful with my posting.

After going through the debugger, I see that I am dereferencing a Null pointer.

My D3D object m_pD3D has a value 0. How can I correct this?

Share this post


Link to post
Share on other sites
You need to create it.

if (!D3DXCheckVersion(D3D_SDK_VERSION, D3DX_SDK_VERSION))
return E_FAIL;

// Create D3D interface
if( m_pD3D == NULL ) {
if(!(m_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
{
::MessageBox(NULL,"Direct3DCreate9 failed","Creation Failure",MB_OK);
goto LFail;
}
}


or something similar.

EDIT: This assumes that you initialize all your variables appropriately. I.e., start out with m_pD3D = NULL in your constructor or the very beginning of your app before you initialize anything related to D3D.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this