Jump to content
  • Advertisement
Sign in to follow this  
break_r

[.net] AccessViolationException Mind-twister

This topic is 4822 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, Using Beta2 and C++/CLI, I've got a managed class that looks something like this: public ref class GammaRamp { private: D3DGAMMARAMP* m_pGammaRamp; public: GammaRamp() { m_pGammaRamp = new D3DGAMMARAMP; } public: ~GammaRamp() { delete m_pGammaRamp; } ... }; That works fine. Now, when I add another pointer... public ref class GammaRamp { private: D3DGAMMARAMP* m_pGammaRamp; private: D3DGAMMARAMP* pAnotherGammaRamp; public: GammaRamp() { m_pGammaRamp = new D3DGAMMARAMP; pAnotherGammaRamp = new D3DGAMMARAMP; } public: ~GammaRamp() { delete pAnotherGammaRamp; // ERROR! delete m_pGammaRamp; } ... }; It throws an AccessViolationException when trying to delete the new gamma ramp pointer. If I try flipping the deletion order, I get the same AccessViolationException: public: ~GammaRamp() { delete m_pGammaRamp; // ERROR! delete pAnotherGammaRamp; } So what happens when I add yet another pointer (any type of pointer)? public ref class GammaRamp { private: D3DGAMMARAMP* m_pGammaRamp; private: D3DGAMMARAMP* pAnotherGammaRamp; private: D3DLIGHT9* pSomethingUnrelated; public: GammaRamp() { m_pGammaRamp = new D3DGAMMARAMP; pAnotherGammaRamp = new D3DGAMMARAMP; pSomethingUnrelated = new D3DLIGHT9; } public: ~GammaRamp() { delete pSomethingUnrelated; delete pAnotherGammaRamp; delete m_pGammaRamp; } ... }; It no longer throws an AccessViolationException! =) Any ideas as to what is going on here? Regards.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
What if you put a breakpoint in your destructor? Could it be that you're deleting the same instance twice?

Share this post


Link to post
Share on other sites
Yes, i've tried breakpoints, but no hint as to what's going on yet. Deleting a null pointer is a safe operation in C++.

Share this post


Link to post
Share on other sites
And now it suddenly works...like magic. I didn't change anything. Mysterious behavior indeed. I'm hoping it's nothing more than the beta2 IDE and not my code =)

However, any insights into AccessViolationException would be much appreciated.

cya.

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!