Sign in to follow this  
godsenddeath

D3D device pointer somehow becomes invalid??

Recommended Posts

godsenddeath    182
__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.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = hWnd;

	d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,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 this post


Link to post
Share on other sites
Ra    1062
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 this post


Link to post
Share on other sites
Ra    1062
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 this post


Link to post
Share on other sites
godsenddeath    182
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 this post


Link to post
Share on other sites
Ra    1062
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 this post


Link to post
Share on other sites
godsenddeath    182
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 this post


Link to post
Share on other sites
Ra    1062
HRESULT hr = d3d->CreateDevice(...);

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

Share this post


Link to post
Share on other sites
Ra    1062
In hex that is 0x8876086C, which is D3DERR_INVALIDCALL.

This thread may help you fix the problem.

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 this post


Link to post
Share on other sites
Evil Steve    2017
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 this post


Link to post
Share on other sites
legalize    116
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.

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