# D3D device pointer somehow becomes invalid??

## Recommended Posts

__vfptr = CXX0030: Error: expression cannot be evaluated this is the error i'm getting when i call Clear() via my LPDIRECT3DDEVICE9 from what i've read this error has something to do with a pointer pointing to an invalid address here is all the code that affects it or includes it in any way.


LPDIRECT3DDEVICE9 d3ddev;

void initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);

D3DPRESENT_PARAMETERS d3dpp;

ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.hDeviceWindow = hWnd;

D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&d3ddev);
}

void render_frame()
{

d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,40,100),1.0f,0);

d3ddev->BeginScene();

d3ddev->EndScene();

d3ddev->Present(NULL,NULL,NULL,NULL);

return;
}

void cleand3d()
{
d3ddev->Release();

d3d->Release();

return;

}



##### Share on other sites
Check the return value of CreateDevice (as well as the other calls). It's a HRESULT that indicates whether there was an error or not.

##### Share on other sites
what would the return be if there's an error? a non-zero number?

##### Share on other sites
Any value less than 0 is considered failure (HRESULTs are signed). FAILED(hr) is a macro that'll check the HRESULT and give you a boolean value.

##### Share on other sites
oh ok thanks alot, and you were right to look at CreateDevice() , but i'm completly new to DirectX and i have no idea whats wrong with it, i've traced my
D3DPRESENT_PARAMETERS, LPDIRECT3D9 and LPDIRECT3DDEVICE9 all the way down the line and i can't see a problem

##### Share on other sites
What number is the error? Did you look it up in the documentation?

Quote:
 DirectX SDK - IDirect3DDevice9::CreateDevice()If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be one of the following: D3DERR_DEVICELOST, D3DERR_INVALIDCALL, D3DERR_NOTAVAILABLE, D3DERR_OUTOFVIDEOMEMORY.

##### Share on other sites
thi may be a dumb question, but how would i check for the accual return value?

all i put was:

if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,hWnd,		D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&d3ddev)))	{		MessageBox(NULL, "Didn't Work", "ERROR", MB_OK|MB_ICONINFORMATION);	}

##### Share on other sites
HRESULT hr = d3d->CreateDevice(...);

Set a breakpoint right after it in the debugger and check the value of hr.

##### Share on other sites
the result was hr -2005530516 HRESULT

##### Share on other sites
0x8876086c

the corresponding constant is D3DERR_INVALIDCALL which means nothing to me :s

##### Share on other sites
In hex that is 0x8876086C, which is D3DERR_INVALIDCALL.

Nevermind.. that's using the ref device. I'm not sure what the problem could be. Google isn't turning up a lot of information, but either one of your parameters is wrong or your card doesn't support something you're trying to access.

##### Share on other sites
oh ok, that may be the problem, i've got horrible integrated graphics, is there any way to use just software rendering?

##### Share on other sites
Quote:
 Original post by godsenddeathis there any way to use just software rendering?

Pass D3DDEVTYPE_REF instead of HAL to CreateDevice.

##### Share on other sites
First, you should really be checking all your "important" D3D return values. Particularly ones that returns a pointer (Such as Create*() Lock(), etc). If any of those functions fail and you don't notice, you'll end up dereferencing null (or worse, undefined) pointers and crashing at best the next time you reference it, and at worst at some random point in your app.
It's a good idea (although I admit I don't bother) to check ALL your D3D functions with a macro that asserts or something in debug builds, and compiles way in release builds, and use that for non-essential calls.

Second, the debug runtimes ar invaluable. In this case in particular, they'll tell you exactly what's wrong - if a D3D function fails, they'll ALWAYS give you a useful message in the debug output, telling you why the function failed. Such as "D3D(ERROR): ValidatePresentParameters(): BackBufferWidth cannot be 0. CreateDevice fails with D3DERR_INVALIDCALL" - which is possibly the problem you're seeing.

To install the debug runtimes, go to the DirectX control pannel (In the Windows control pannel in older SDKs, in the DirectX SDK folder -> tools in the start menu in more recent SDKs), and make sure "Use Debug Runtime" is selected.

Although, if the debug runtimes tell you what's wrong, and you fix it, it's still extremely important to check your return values. Just because it works on your hardware, doesn't mean it'll work on someone elses.

Also, slightly unrelated - the reference rasterizer isn't really for checking bugs like this. It might show them up, but it won't be as useful as the debug runtimes. The ref rast is so you can test things not supported by your hardware, such as advanced pixel shaders, and is for use if you think you have a driver bug (If a HAL and REF device behave differently, it's almost always the REF device that's correct, and the HAL device is buggy, meaning bad drivers).
Finally, the ref device is only available on machines with the SDK installed. You can't expect end users to have it installed at all.

##### Share on other sites
Everything Evil Steve said is great.

If you want a more verbose treatment/explanation of those issues, look at my book. From the way you are talking, it sounds like you are completely new to Direct3D and don't know a thing about it, so instead of pointing you to specific chapters, I'd just recommend you read the whole thing.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627662
• Total Posts
2978519

• 10
• 10
• 12
• 22
• 13