[C++-sig] boost.python - C++ class overridden in python causes slicing

troy d. straszheim troy at resophonic.com
Tue Sep 8 21:55:56 CEST 2009


Jean-Sébastien Guay wrote:
> Hi again Troy,
> 
>> I was thinking of setting up a googlecode project for this work, 
>> because there is at least one other person who might be interested in 
>> working with me on it (Paul Melis). I'll see if I can do that soon.
> 
> It's done now, here:
> 
> http://code.google.com/p/osgboostpython/
> 
> Note that I do my work on Windows, I've tried to make my boost-build.jam 
> and Jamroot as platform-independent as possible but you may have to 
> tweak some things to make it build/run. You'll need OSG_ROOT and 
> BOOST_ROOT pointing at the right places for it to build.
> 
> Once the python modules are built, copy them into lib/osg, lib/osgGA, 
> lib/osgDB and lib/osgViewer (I've scripted that for Windows but I should 
> really make a "stage" rule in the jam script, feel free to do it if you 
> want).

[reply taken offlist]

I work mostly on linux, so I suppose we can clean up after one another. 
     but why mess with boost.build?  Are you familar with / do you 
prefer cmake?   Boost 1.38-40 build fine with cmake.

I'll look a little further...

-t


> 
> Then run
> 
>   python test/osg/test.py 9
> 
> (the 9 runs test #9 only, the file contains 10 different tests)
> 
> That will work, it will print the following:
> 
>   python apply_Group - node name: g1
>   python apply_Group - node name: g2
>   python apply_Node - node name: n
> 
> You'll see the problem if you comment out the apply_Group method of the 
> DerivedVisitor class in test/osg/test.py. Then it will only print out:
> 
>   python apply_Node - node name: g1
> 
> when it should print out:
> 
>   python apply_Node - node name: g1
>   python apply_Node - node name: g2
>   python apply_Node - node name: n
> 
> which is what the C++ code attached does.
> 
> You'll also see in test/osgViewer/test.py the other test I was referring 
> to, the NodeCallback test. If you change the code to set the callback as 
> CullCallback instead of UpdateCallback, you'll see that the model will 
> no longer be displayed, even though traverse() is being called. The C++ 
> code attached also demonstrates that this should not happen - the model 
> should still be displayed after setting a CullCallback as long as the 
> callback calls traverse(). (you can comment out traverse() in the 
> callback's operator() method to see that the model will no longer be 
> displayed).
> 
> I hope this helps you help me :-)
> 
> I just had a thought, maybe I need to wrap the traverse() methods in 
> osg::Node and osg::Group? Would that allow call_method to call the right 
> one and not slice off the argument? I had not wrapped them because in 
> general I don't think they'd be useful in python code, but maybe they're 
> necessary for this to work? I'll try that and see.
> 
> Thanks in advance,
> 
> J-S
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig



More information about the Cplusplus-sig mailing list