Jump to content
  • Advertisement
Sign in to follow this  
crivens

Boost Python - C++ class' private static data blown away before accessing in Python?

This topic is 3750 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've exposed a C++ class to Python using Boost Python. The class, let's say it's called Entity, contains private static data, which is an array of strings. Though I think it implements it using MFC's CPtrArray. I've also exposed a public function from Entity - let's say it's called foo. This function accesses the private static data (the string array). I have multiple instances of Entity stored in a custom C++ container, which is also exposed to Python as class EntityList. In Python, I retrive an Entity from the EntityList:
elist = EntityList()
elist.append(Entity())
elist.append(Entity())

entity = elist.get_at(0)

entity.foo()



But it crashes inside foo() as the private static data is empty; or rather the string array is empty. I know before that point that the private static data is valid when accessed earlier by the C++ code as the program works fine. It just won't work from Python, so somehow the private static data has been blown away but I can't work out where or why. The static data is setup at initialisation - my Python code is only called long after initialisation is complete. I know this is an impossible question to ask, but can anyone think of something obvious I need to look into? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I added a static dump() function to the Entity class that dumps the string array, and even if I just do the following in Python:

Entity.dump()


in Python, the private static data is empty. Doing the same from C++ works fine. Weird.

Share this post


Link to post
Share on other sites
Embedded. I think it's a dll boundary problem - I think the Python module has its own copy of the static data, which hasn't been initialised.

Share this post


Link to post
Share on other sites
From your original post, I would certainly hope it has its 'own' copy of the data; where else could it be?

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!