[C++-sig] Problems getting to grips with Boost v2.0

Oliver Malham oliver.malham at savageparsnip.com
Tue Nov 5 00:09:33 CET 2002


	First off, let me congratulate everyone who has contributed to
Boost.Python on producing such an excellent library. (And I'm sorry if
this question is a bit long winded ;-)

	I'm currently working on a game engine that will use Python as the
ingame scripting language that controls everything. A key part of this
functionality is building the scenegraph for the current level. This
takes the form of a tree of objects which are created by a factory
object, and passed about as object pointers (the factory class manages
the object's lifetime). Building a basic scenegraph in C++ works fine;
however building the same scenegraph through the python interface
doesn't seem to setup the scenegraph properly (the scenegraph object
complains about being empty). I'm not sure where I've gone wrong, and
would appreciate it if you could point me in the right direction.

Here's the code involved:


// Scene object manages scenegraph, user IO, AI, etc.
  .def("activate", &Scene::activate)
  .def("sleep", &Scene::sleep)
  .def("cleanup", &Scene::cleanup)
  .def_readonly("scenegraph", &Scene::scenegraph) // Member class

// Scenegraph handles all drawable objects
  .def("setStart", &SceneGraph::setStart) //Takes SceneGraphNode pointer

// Base scenegraph node object
  .def("type", &SceneGraphNode::type)

// Very simple object just clears the screen to blue
class_<BlueScreen, bases<SceneGraphNode> >("BlueScreen")
  .def("type", &BlueScreen::type)

// Factory creates and owns all dynamically built objects
  .def("newScene", &Factory::newScene, return_internal_reference<>())
  .def("newBlueScreen", &Factory::newBlueScreen,


And the Python code that builds the scenegraph:

from KeiPy import *

factory = Factory()

scene = factory.newScene()
bluescreen = factory.newBlueScreen()

When this enters the game's main loop, I get messages from the
constructors for the scene, scenegraph and bluescreen objects. From my
debug messages it looks like the bluescreen object is being assigned to
a different scenegraph object than the one constructed, which has me
just a bit confused.

Thanks for any advice you can give me, and I hope I'm not being stupid
and wasting your time ;-)


Oliver Malham

Software Engineer
Savage Parsnip Games

More information about the Cplusplus-sig mailing list