Sign in to follow this  
poly-gone

Calling SAFE_RELEASE(m_pd3dDevice) causes an access violation

Recommended Posts

This is really strange and I've never had this problem, but calling SAFE_RELEASE(m_pd3dDevice) causes an access violation. Could anybody point out why this is happening. Thanks.

Share this post


Link to post
Share on other sites
You've most likely trashed the m_pd3dDevice pointer, or its been 'Release'd more times than its been 'AddRef'ed.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
And what happend to debugging, putting break point and inspecting m_pd3dDevice variable.

Share this post


Link to post
Share on other sites
Quote:
Original post by jonnii
are you trying to delete from a different dll or something?

This should never be a problem, because you don't actually delete yourself. Release() does, internally. So it doesn't make a difference, AFAIK, as to where you're calling from.

Share this post


Link to post
Share on other sites
I believe the call to m_pd3dDevice->Release() returns the number of references that the device still has. You can check by doing something like this:

DWORD Result = m_pd3dDevice->Release();

The result should be zero when you are releasing the device.

Share this post


Link to post
Share on other sites
Quote:
Original post by _Phalanx_
what about

if(m_pD3DDevice)
m_pD3DDevice->Release();



wouldnt that do the same thing? try it


This is the SAFE_RELEASE macro:


#define SAFE_RELEASE(p){if(p)p->Release();p=0;}

Share this post


Link to post
Share on other sites
I guess I should've explained better :) The device is created properly and it even renders the scene. But during the cleanup phase, calling SAFE_RELEASE(...) causes an access violation. The strange thing is that when I run the app through visual studio, it runs fine and exits fine, but when I "directly" run the app, it gives the access violation on exit.

The whole "thing" is encapsulated in a dll so I was wondering if that would affect things, doesn't make sense, yet...

Anyway, calling SAFE_RELEASE(...) when the device hasn't been created shouldn't give any problems since m_pd3dDevice would be NULL and the macro would simply ignore the call.

Thanks for the replies guys, I appreciate it. Any more ideas?

Share this post


Link to post
Share on other sites
Hmm..

just make sure you haven't released device earlier. Check if you haven't somewhere assigned pointer to d3d device into another variable (than m_pd3dDevice) and used SAFE_RELEASE onto that variable.

Share this post


Link to post
Share on other sites
Thanks for replying but I already got the problem solved. A string encapsulation class that I wrote had some bugs in it that were causing a lot of weird problems, including this one (don't know exactly how). I re-wrote that class and now everything seems to be fine. Thanks for all your inputs guys.

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