Sign in to follow this  

This makes no sense!

This topic is 4340 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 am having a problem when I close my program. For some reason, I get this error: Unhandeled exception in 3DGameModeler : 0xC0000005 : Access Violation. I only get the error when I add this line of code to my CModel class: VERTEX *m_pTempLineVerts; The error is caused by the ID3DXEffect when the destructor is called. All I am doing is releasing the ID3DXEffect using : m_pEffect->Release (); The Effect is completely seperate from the model so I don't know why one is affecting the other. If I remove the TempLineVerts, everything is fine, but if that line is there, it crashes when I close the program. Unfortunatly it is one of the most essential of the program because it makes it possible for me to render the lines. The error happens as soon as I add an extra pointer to my CModel class (i tried UINT *pTemp). Does anyone know why this is happening?!?

Share this post


Link to post
Share on other sites
It could be anything. If you have a buffer overrun somewhere in your code, or you did not properly release a resource, or you used an unitilized pointer, or you have race conditions (multithreaded only issue).

Share this post


Link to post
Share on other sites
It looks like the pointer is uninitialized but I use it all the time in the code. My entire render function uses the m_pEffect but when I try to release it, the compiler says that it is not defined.
What would be causing that?

Share this post


Link to post
Share on other sites
Ok I found the problem. I was releasing the resource twice. Once with the Free function while I was shutting down the program. Then once again when the destructor was called.

One thing I still don't understand is that if I don't call the Free function before and I only use the destructor, there is an error. But if I only use the Free function and I tell the destructor to do nothing, it works. Any ideas why?

Share this post


Link to post
Share on other sites
before releasing anything in DX you should do this:

if (m_pEffect) {
m_pEffect->Release();
m_pEffect=NULL;
}

to simplify this code you should be able to find a macro called:

SAFE_RELEASE(m_pEffect);

this does the same thing as above.

now you can be sure that you will not release something that is already released.

for good programming practise I would also recommend doing something similar for regular pointers:

#define SAFE_DELETE(p) if(p){delete p; p=NULL}

Share this post


Link to post
Share on other sites
Quote:
Original post by mmakrzem
#define SAFE_DELETE(p) if(p){delete p; p=NULL}

Sorry for beating a dead horse... "if (p)" is redundant.
    #define SAFE_DELETE(p) { delete p; p=NULL } 

Share this post


Link to post
Share on other sites

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