Sign in to follow this  

Error when accesing to 0x00... I don't understand!!!

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody!!! I'm creating my class CTriangle trying to simplify my code. This class has in his private part (with other vars...): LPDIRECT3DDEVICE8 cpy_pD3DDevice; LPDIRECT3DVERTEXBUFFER8 cpy_pVertexBuffer; The constructor of this class is CTriangle(LPDIRECT3DDEVICE8 p3DDevice). So, when I create one, I pass the main D3D Device. I'm very surprised, because I'm getting an error when accesing to 0x0000 when creating the vertex buffer (cpy_pD3DDevice->CreateVertexBuffer...). I've used my debugger and I've seen how apparently that copy is not made... cpy_pD3DDevice = 0x00000000 , but in CTriangle constructor the first asignation is: cpy_pD3DDevice = p3DDevice. I've tried with passing by reference, but i've got the same error. Thanks a lot!

Share this post


Link to post
Share on other sites
Is your device properly setup when you call the CTriangle constructor?

This is how I do it in my code:
CCamera::CCamera(IDirect3DDevice9*& pDevice)
{
pD3DDevice = pDevice;
}


where pD3DDevice is of type IDirect3DDevice9*, resp. LPDIRECT3DDEVICE9

regards

Share this post


Link to post
Share on other sites
You're passing the device in as NULL. In other words, you tried creating a device, but it didn't create properly. Show us your code for creating the D3D Device and what you set all of the parameters to (i.e. your entire present parameters structure).

Chris

Share this post


Link to post
Share on other sites
Oooopsss...

Thank you very much for your answers but it seems that i'm tired... :P

Yeah, i was passing the object like NULL ... because I haven't created at this moment...

When iniciated D3D correctly ( And LPDIRECT3DDEVICE8 of course) I've used CTriangle without problems.

Sorry!!! :)

Share this post


Link to post
Share on other sites
When passing in pointers like that into constructors, I always use an assert statement to check for NULL :) (really, NULL should be checked for before even constructing the class, but the assert is a final safety barrier -_^).

Share this post


Link to post
Share on other sites
Also, check this out. It's suggested (though you don't have to) to use a singleton class that all of your other classes can access and have the device pointer stored there. For instance, each class can access the graphics manager and then get the Device pointer from there. It's a tradeoff though. You get 2 levels of indirection while storing fewer pointers. But indirections are harmless when initializing, because that's something you won't do every frame. Passing in the Device pointer to the triangle class and saving it there will add an extra 4 bytes for every class you create, which in the case of triangles could be a lot of memory savings.

The other advantage is that DirectX may decide to change the name from Direct3DDevice9 to Direct3DDevice10...and will. So, if you just have a function in all of your other classes that says:

GraphicsMgr->GetDevice()->DrawPrimitive(...) (by the way GetDevice is a good candidate for being inline)

There's nothing to change. But, if you have Direct3DDevice9 *pDevice stored in every other class, you have to go through all of them and change it to 10...albeit that's really not THAT big of a deal. It's just something else to consider.

Good luck,
Chris

Share this post


Link to post
Share on other sites

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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