On 09/22/2010 04:09 PM, res wrote:
> On 22.09.2010 21:58, Sebastian Hoffmann wrote:
>> My code segfaults when calling iPcLinearMovement.SetPath() in this code:
>>      def pccommandinput_moveplane1(self,pc,args):
>>          p = csPath(2)
>>          p.SetForwardVector (0, csVector3(1,0,0))
>>          p.SetPositionVector(0, csVector3(-2,0,0))
>>          p.SetUpVector      (0, csVector3(0,1,0))
>>          p.SetTime          (0, 0.0)
>>          p.SetForwardVector (1, csVector3(-1,0,0))
>>          p.SetPositionVector(1, csVector3(2,0,0))
>>          p.SetUpVector      (1, csVector3(0,1,0))
>>          p.SetTime          (1, 1.0)
>>          self.mover.SetPath(p)
>> Running celstart in gdb shows this call and code line to be the cause:
>>
>> 0x00007fffe1d98861 in celPcLinearMovement::ExtrapolatePosition
>> (this=0x7fffe34f8fb0, delta=0.104999997) at
>> /home/baribal/src/CEL_latest/plugins/propclass/move/linmove.cpp:1093
>> 1093     float end_time = path->GetTime (path->Length () - 1);
>
> I looked into the generated Python bindings code.
>
> What happens is that, behind the scenes, a “csPath*” is stored inside p.
> So when p gets out of scope, a “delete” is done on the stored pointer.
> Obviously this is wrong, since the SetPath() call stores a reference to
> ”p”. (It takes an iPath*.)
>
> What _should_ happen is that, behind the scenes, a “csRef<>” should be
> stored in p (resp. that, instead of a ”delete”, DecRef() should be used
> when p is destroyed).
> SWIG probably allows that. However, I have no idea to actually do that.

Perhaps an explicit csPath -> iPath typemap is needed. The typemap would 
make a local reference-counted copy of the input csPath, hand the copy 
to low-level SetPath(), and then decrement its own reference to the 
copy. The original input csPath can then go out of scope without causing 
harm to the path ultimately handed to setPath().

-- ES

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Cel-main mailing list
Cel-main@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cel-main

Reply via email to