Jump to content
  • Advertisement
Sign in to follow this  
cppcdr

This makes no sense!

This topic is 4553 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
Advertisement
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
Or use boost's smart pointers. Not only do they stop errors like this from being possible, you don't even have to think of where to call any destructors.

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
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!