Create D3D device error

Started by
10 comments, last by Buckeye 15 years, 9 months ago
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.
Advertisement
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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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)?
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.
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).
Hah! Missed it the first couple times around.

It should be:

CreateDevice(..., &m_pDevice);

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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.
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.
Quote:Original post by Drats
Could you tell me how do I use the debugger? Is there like a a guide on the net that could perhaps tell me?


Yes there is.
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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement