09 March 2006

Object Identity Crisis

Opioid2D has progressed pretty nicely, and I now have working C++ code for displaying an O2D-sprite on screen via a Python API. While writing the sprite test, I came upon a very unfortunate "feature" of SWIG that I wasn't aware of before. As this was the first time I've really used SWIG, I wasn't really sure how the class wrapping mechanism works. It turns out that SWIG creates a "shadow" object in Python, which has a pointer to the live C++ object and the problem is that, as far as I know, SWIG doesn't do any tracking between the two, so once the C++ object is passed to the framework machinery, it pretty much becomes detached from its Python twin.

I have a cunning theory on how to solve this pretty transparently, but this will slow down development somewhat until I can design and implement a working solution. I guess I could go read on the Python extension API and write my own wrappers in C, but that seems a bit daunting at this point, compared to the relative ease that SWIG has provided. We'll see...

0 Comments:

Post a Comment

<< Home