I don't use Luabind either but osgswig with Python instead. I sometimes
experience similar surprising effects when passing non-declared variables as
function arguments. In that case, the reason for this is often that the
scripting language garbage collector deletes the Vec3f after returning from
the function, essentially leaving any references to the Vec3 dangling. A
correct reference counting mechanism in the scripting binding should prevent
this in most cases.

The problem you're describing could have similar cause. So just to be sure,
try and define the Vec3f in the global scope and pass a reference as an
argument in your call.:
myvec= Vec3f(2,0,0)
entMan:createStaticEntity( "ball", myvec, false )
Or, in this function, try and make a copy of the parameter values before
returning.

regards,
Gerwin


On Wed, Nov 12, 2008 at 8:14 AM, Dusten Sobotta <[EMAIL PROTECTED]>wrote:

> Hello,
>
> I've been working on an engine that combines sdl, osg, bullet, open al, and
> now lua for roughly 6 weeks.  Static and dynamic entity creation works well
> on the fly if handled with C++ code, however if I attempt to off-load this
> logic to lua, I run into problems.  Below is an example of code that is
> relevant to the problem:
>
> ////////////////////////
> void entityManager::loadStaticEntityList( const std::string& filename ) {
>
>     lua_State *L = lua_open();
>     luabind::open(L);
>
>     luabind::module( L ) [
>
>     luabind::class_<osg::Vec3f>("Vec3f")
>         .def( luabind::constructor< float, float, float >() )
>     ];
>
>     luabind::module( L ) [
>
>     luabind::class_<entityManager>("entityManager")
>         .def( luabind::constructor< >() )
>         .def( "createStaticEntity", &entityManager::createStaticEntity )
>         .def("destroyAllEntities", &entityManager::destroyAllEntities )
>     ];
>
>
>     if( luaL_loadfile( L, filename.c_str() ) || lua_pcall( L, 0, 0, 0 ) )
>         throw "could not load entity list";
>
>
>     createStaticEntity( "ball", osg::Vec3f( 0, 0, 0 ), false ); //direct
> C++ call; works!
>
>     luaL_dofile( L, filename.c_str() );
>
> }
> ///////////////////////////
>
> ///////////////////////////
> void entityManager::createStaticEntity( const std::string& type, const
> osg::Vec3f& position, const bool& dimension ) {
>
>     entity * newEntity = createEntityP( type, position, dimension );
>     _physicsManager->defineRigidBody( newEntity, type, false, dimension );
>
>     entities[ newEntity->getRigidBody() ] = newEntity;
>     staticEntities[ dimension ]->addChild( newEntity->getPAT().get() );
>     staticEntityList.push_back( newEntity );
> }
> ///////////////////////////
>
> And here is the lua script I'm trying to run:
>
> ------------------------------
> entMan = entityManager()
> a = Vec3f( 0, 0, 0 )
>
> --same call from within lua; crashes the engine if uncommented!
> entMan:createStaticEntity( "ball", Vec3f( 2, 0, 0 ), false )
> ------------------------------
>
>
> As you can see, a declaration of type Vec3f works from within lua, so I
> don't think that using Vec3f as a parameter is an issue.
> Might anyone know what's going on here?  I'm not very familiar with
> luabind, and even less familiar with getting it to play nicely with OSG.
> Any help would be greatly appreciated.
>
>
>
> Thanks for your time,
>
> Dusten
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to