Jump to content
  • Advertisement
Sign in to follow this  
Jacob84

Different kind of copies?

This topic is 5176 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

I'm still developing my class hierarchy , just to learn, like that: · CObject (Base) -> CTriangle CObject has in his protected part: LPDIRECT3DDEVICE8 cpy_pD3DDevice; LPDIRECT3DVERTEXBUFFER8 cpy_pVertexBuffer; pD3DDevice is passed by the CTriangle constructor and cpy_pVertexBuffer is "created" in the CTriangle CreateVertexBuffer() function. The problem comes in CObject destructor (~CObject()) when i do this: if(cpy_pD3DDevice != NULL) { cpy_pD3DDevice->Release(); cpy_pD3DDevice = NULL; } if(cpy_pVertexBuffer != NULL) { cpy_pVertexBuffer->Release(); cpy_pVertexBuffer = NULL; } cpy_pD3DDevice , a copy from g_pD3DDevice is released without problem, but I got an error when trying to release cpy_pVertexBuffer. The error comes when I close the program (obviously) and is: Trying to read 0x0014c844. Is strange, but in the "local vars" window of my debugger the direction of cpy_pVertexBuffer is 0x00181820. Well, if someone can help me, it will be very appreciated. I can solve the problem not releasing cpy_pVertexBuffer, but I would like to know why. Bye! :)

Share this post


Link to post
Share on other sites
Advertisement
Maybe the vertex destructor needs a valid device to destruct itself (maybe internally, it tells the video card to destroy that vertex buffer)? Try changing the order of deletion.

Share this post


Link to post
Share on other sites
Ey thanks JoeyBlow2!!!

I've solved the problem in part with your help. I've found something that there isn't in the tutorials usually :)

I supose that LPDIRECT3DDEVICE8 has his constructor copy programmed in a special way, and every copy of this object is linked to the object where the copy was made. Is possible that only one LPDIRECT3DDEVICE8 object can exist?

I've suposed that because I was deleting in my main program ( Not in the class with the copy of LPDIRECT3DDEVICE8 , in the main program!) LPDIRECT3DDEVICE8 g_pD3DDevice and then cpy_pD3DDevice, the object that i've suposed that was a copy but...

Thx!!!

PS: Thinking after wrote this post...i'm not sure what constructor copy is programmed in a special way, LPDIRECT3DDEVICE8 or LPDIRECT3DVERTEXBUFFER8... Can anybody bring some light on the topic??? :)

Share this post


Link to post
Share on other sites
LPDIRECT3D*9 is just a pointer to an IDirect3D*9 interface. When you copy instances of that, you're copying pointers to interfaces (which are part of objects).

What you should do is increment the interface reference count on copying, e.g.
cpy_pD3DDevice = g_pD3DDevice;
g_pD3DDevice->AddRef();


By incrementing the reference count, you're saying: I want to use the device in my class. Add 1 to the list of "D3D Device users". When you're done (i.e. are in the destructor), you release it, saying "Remove me from the list of device users. I don't want it anymore".

When the reference count reaches 0, the device will be destroyed.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!