[Bf-python] Python bug with user counts

Martin Poirier theeth at yahoo.com
Mon Jan 22 00:49:44 CET 2007


Hi,

--- Ken Hughes <khughes at pacific.edu> wrote:

> I think this might be a show-stopper bug, but before
> trying to fix 
> thought I should discuss here:
> 
> I chased a segfault/memcorruption problem for about
> three hours this 
> morning before finding the cause.  The problem is
> with Python objects 
> being users of Blender data (i.e., id.us).  To make
> a long story short, 
> when an exception happens Object_dealloc() isn't
> called, so any BPy 
> Objects existing at that point leave the real
> Blender objects with an 
> incorrect number of users.  After reloading the
> .blend file and running 
> the script again (or a few times, it varies) would
> cause a crash.

Was the BPyobject allocated in the top level namespace
(global) or was it in an inner scope (function, class,
method, ...)?

If yes, there's a good reason why it wasn't
deallocated. We reuse the same global namespace
between each script so they can share values. (if that
is a good idea is debatable), so the BPyobject would
have persisted there, even if the script threw an
exception.

> I verified this also happens with 2.42a.
> 
> The simplest solution is to get rid of the id.us
> manipulation.  But how 
> many script rely on this now?

It's a two way problem. If we stop making BPy a user
of Blender's data, we have to track when that data is
removed to invalidate any BPy object referencing it.

> The next solution would be to correctly deallocate
> objects when an 
> exception is thrown.  But I don't know how to do
> that or if it's 
> possible.  If we go that route, does anyone know how
> to do it?

I don't, but as I said earlier, the non-deallocation
might be normal (if it isn't, I'd say it's a bug in
Python's implementation).

Martin


 
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html 



More information about the Bf-python mailing list