[Bf-python] CurNurb/IpoCurve/BezTriple hackery

Ken Hughes khughes at pacific.edu
Sat Jun 18 21:52:47 CEST 2005


Stephen Swaney wrote:
> On Sat, Jun 18, 2005 at 10:57:42AM -0700, Ken Hughes wrote:
> 
>>No argument here; they're not good code.  But in
>>Python I would expect this to throw an exception.
>>
>>>You can do the same thing is C by allocating an array and
>>>setting another pointer to it.  If you then realloc the
>>>array, the held pointer is probably not valid.
>>
>>Yes, but C isn't OO; it easy for a programmer to do things which
>>will corrupt memory.   Python should be better than that.
> 
> 
> You can do the same thing in C++, but let's not go there!

Couldn't agree more :-)

>...
> The heart of our problem is that a BezTriple is not a
> separate and unique blender datablock like Camera, or IpoCurve
> that exists by itself.  BezTriple is a dynamically allocated
> part of a Nurb struct.

Exactly.

> One way to get around this problem is to change the bpy BezTriple
> implementation so that it holds a pointer to the Nurb that contains
> our BezTriple and an index to the specific array element we want.
> This way, a BezTriple becomes, in a sense, a convenience function for a
> particular array element. Also, trying to access a deleted point can at
> least throw an execption.

Right.... but I think the Nurb would also need pointers to its
BezTriples (or the Nurb point list, should we decide to wrap those
later) so the same problem doesn't happen if the Blender Nurb is deleted
out from under the curve points.

> Note 1: You can argue this is just pushing the problem one level up
> since Nurbs are not separate datablocks either, but merely elements in
> a dynamically allocated list.  So it is still possible to hose things.

See http://projects.blender.org/pipermail/bf-python/2005-May/002753.html
Been there, done that :-)

> Note 2:  When we do Blender3 and have actual python data
> structures instead of wrapping C data, this thread can come to an end!

And someone else will start a new one :-p

Ken

(PS; I'll summarize this thread on the wiki page later).



More information about the Bf-python mailing list