Jump to content
Sign in to follow this  
  • entries
    195
  • comments
    198
  • views
    104251

You too can learn from my mistakes

Sign in to follow this  
SiCrane

91 views

I was working on a C++ project that I just started adding embedded Python support to, and I while testing the Python exception handling I kept getting these strange errors Fatal Python error: unexpected exception during garbage collection when generating Python exceptions, and I just couldn't figure out where that was coming from.

Long story short: I had wrapped Py_Initialize() and Py_Finalize() in a class' constructor and destructor to apply RAII so I wouldn't forget to call Py_Finalize(). Unfortunately, I had created an instance of the class inside the try block that I was using to handle the exceptions. So when the exception was thrown, the stack unwound and Py_Finalize() was called while Python had it's pants down (metaphorically speaking). Boom.

The irony is that the problem only showed up in test code, and wouldn't have been a factor in any of the actual usages in the application because of the way that I was initializing Python. At least, I now know one possible cause for that kind of error, and have something to look for the next time I see something like it.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

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