943,831 Members | Top Members by Rank

Ad:
Jul 3rd, 2009
0

LPDIRECT3DDEVICE9 ... failed?

Expand Post »
Hey All

I am trying to create a DLL to handle some directx for me. But it seems to be acting up. If you take a look at the picture below you will see that the LPDIRECT3DDEVICE9 d3ddev; pointer is not being created? While at the same time, the D3DPRESENT_PARAMETERS d3dpp; is.

http://www.exsolved.com/media/d3d.jpg

The directx header is being included at the top of the file like so:

#include <d3d9.h>
#pragma comment (lib, "d3d9.lib")

Everything else directx wise works except for

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;

Is there a reason LPDIRECT3DDEVICE9 d3ddev; & LPDIRECT3D9 d3d; are not being created?

Thanks a ton.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eXsolved is offline Offline
14 posts
since Jun 2009
Jul 4th, 2009
0

Re: LPDIRECT3DDEVICE9 ... failed?

You're just creating a pointer variable without actually setting it to anything, so what you're getting is 'worse' than a null pointer, it's a pointer to some random location. The message in the screenshot is caused by the debugger trying to treat whatever's at that random location as a direct3d device, which it almost certainly isn't.

You have to call a function (and I don't remember which one) to actually create and return a direct3d device, then store a pointer to it in a LPDIR...CE9 variable.

Are you following a tutorial or trying to assume/guess how to do things? I would suggest looking at some working source code that uses the API before trying to use it yourself.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Jul 4th, 2009
0

Re: LPDIRECT3DDEVICE9 ... failed?

Oh, and the reason that a D3DPRESENT_PARAMETERS object 'just works' is that the D3DPRESENT_PARAMETERS is a value (structure) type not a pointer type.

Learn this distinction ASAP.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Jul 4th, 2009
0

Re: LPDIRECT3DDEVICE9 ... failed?

No, I believe I am setting it to something, but during that setup its failing. Here's the exact function taken straight out the DLL source code:

extern "C" e2api void initDirectX(HWND &handle, int windowed, int width, int height)
	{
		d3d = Direct3DCreate9(D3D_SDK_VERSION);

		D3DPRESENT_PARAMETERS d3dpp;

		LPDIRECT3D9 d3d;
		LPDIRECT3DDEVICE9 d3ddev;

		ZeroMemory(&d3dpp, sizeof(d3dpp));
		d3dpp.Windowed = windowed;
		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		d3dpp.hDeviceWindow = handle;

		d3d->CreateDevice(D3DADAPTER_DEFAULT,
						  D3DDEVTYPE_HAL,
						  handle,
						  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
						  &d3dpp,
						  &d3ddev);

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

However, it keeps crashing everytime d3ddev is called... usually crashing at the line:

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

So I added a breakpoint just above that line, and when hovering over d3ddev, it says "iUnknown {...}".

Any ideas mate?

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eXsolved is offline Offline
14 posts
since Jun 2009
Jul 5th, 2009
0

Re: LPDIRECT3DDEVICE9 ... failed?

Does this have something to do with the fact that I am calling DirectX from within a DLL? I have never worked with DLL's before so I am assuming things. Other than that, are you allowed to create/use variables within a DLL?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eXsolved is offline Offline
14 posts
since Jun 2009
Jul 5th, 2009
0

Re: LPDIRECT3DDEVICE9 ... failed?

Ah ok. There shouldn't be any problem with doing what you're doing from a DLL. I have only ever written DX applications that are staticly linked and DLLs that don't do anything DX, so I don't know for sure if there are any specific issues with DX calls in DLLs, but I would think that it's unlikely to be a problem.

What is the return value from CreateDevice?
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Jul 5th, 2009
0

Re: LPDIRECT3DDEVICE9 ... failed?

I'm not sure how I check that directly, but I added a breakpoint just below the call, and checked d3d as that's holding CreateDevice's return value (I believe), and it's saying the same thing as d3ddev.. "__vfptr = CXX0030: Error: expression cannot be evaluated". So I think the problem is the CreateDevice function itself. Either I am calling it incorrectly, or one or more of its arguments are not quite there.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eXsolved is offline Offline
14 posts
since Jun 2009
Jul 5th, 2009
0

Re: LPDIRECT3DDEVICE9 ... failed?

The function call CreateDevice returns a HRESULT (error code), so do:

HRESULT result = CreateDevice (...);

the possible values are defined as D3D_OK, D3DERR_DEVICELOST, D3DERR_INVALIDCALL, D3DERR_NOTAVAILABLE, D3DERR_OUTOFVIDEOMEMORY ( see http://msdn.microsoft.com/en-us/libr...3(VS.85).aspx).

So do something like:

switch ( result ) {
  case D3DERR_DEVICELOST: std::cerr << "device lost"; break;
  ... etc ...
}

Just to find out what (if anything) DX thinks is going wrong.
Last edited by MattEvans; Jul 5th, 2009 at 10:53 am.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Jul 5th, 2009
0

Re: LPDIRECT3DDEVICE9 ... failed?

Just FYI, the __vfptr = CXX0030 thing is because the debugger thinks that d3ddev is pointing to an actual instance of a D3D device, if there's some error in the call to CreateDevice, and for whatever reason the device isn't created, then the pointer doesn't get assigned a value, and it'll have an 'undefined' value (since you don't initialize the pointer to anything). Basically, if you declare & initialize d3ddev like:
LPDIRECT3DDEVICE9 d3ddev = NULL;
Then, should the CreateDevice call fail to initialize that variable, the debugger will give a less confusing message, i.e. it will report d3ddev as still being NULL (and it shouldn't try to dereference it and complain about a bad virtual function table, which is what that __vfptr is all about)
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Jul 5th, 2009
0

Re: LPDIRECT3DDEVICE9 ... failed?

Thank you for your help mate. But none of this is going the right way, so I am going to take a completely different approach to it. I've got directx working wonderfully countless times using it straight in a win32 app. This DLL stuff is killing me. So, I'll just stick to using it straight in win32.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eXsolved is offline Offline
14 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: Dark GDK
Next Thread in Game Development Forum Timeline: Want an advise with u guyz help me..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC