[Bf-python] CurNurb/IpoCurve/BezTriple hackery

Ken Hughes khughes at pacific.edu
Sat Jun 18 18:23:34 CEST 2005


Stephen Swaney wrote:
> On Sat, Jun 18, 2005 at 07:53:41AM -0700, Ken Hughes wrote:
> 
> The fundamental problem here is the Ipo.getPoints() returns
> as list of coordinates that is a snapshot in time of the current
> curve.  This should be documented behavior.  With any snapshot
> or iterator, if the underlying object is changed by adding new
> elements, the iterator becomes invalid.
>
> I think a better way to do this is to implement operator[] like
> we did with CurNurbs.  Having iterators lets us write
> things like 
> for p in some_ipo_curve:
>   # do something with a point
> 
> This also lets us operate on control points directly via the
> ipocurve[i] syntax and makes Curves and Ipos behave in a similar
> fashion; part of that unification thingie we are talking about.

But if the underlying object is changed, you don't expect for
Python to scribble to memory.  Iterators make it harder to do but
not impossible:

   l=[]
   for p in some_ipo_curve:
      l.append(p)

   some_ipo_curve.addBezier([1,2])
   l[0].setPoint([3,4])	# writes to freed memory

(I forgot about adding iterators to the base class in the stuff
I wrote on the wiki page; will add that.)

>>Either way we go, we have to do the same thing with Ipos and
>>IpoCurves; otherwise
>>
>>  a=Blender.Ipo.Get('ObIpo').getCurve('LocX')
>>  b=Blender.Ipo.Get('ObIpo').getCurve('LocX')
>>
>>gives two different objects manipulating the same data and have the
>>same problems all over again.
> 
> This is standard python behavior for assignment operations.
> If both of these operations return thin wrappers to blender data,
> there is no problem.

True.... bad example on my part.  But

   a = Blender.Ipo.Get('ObIpo')
   b = a.getCurve('LocX')
   a.delCurve('LocX')
   b.setInterpolation('Constant') # accesses freed memory

is the same type of problem.

Again, I'm not proposing that these are or aren't valid things to do
in a BPython script.  I'm just saying I think they shouldn't cause
Blender to malfunction if they do happen.

Ken



More information about the Bf-python mailing list