[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11257] branches/2-44-stable/blender/ source/blender/python/api2_2x/Draw.c: bugfix

Campbell Barton cbarton at metavr.com
Fri Jul 13 07:21:44 CEST 2007


Joe Eagar wrote:
> Campbell Barton wrote:
>> Revision: 11257
>>           
>> http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11257 
>>
>> Author:   campbellbarton
>> Date:     2007-07-12 22:14:16 +0200 (Thu, 12 Jul 2007)
>>
>> Log Message:
>> -----------
>> bugfix
>> * sliders with realtime option enabled did not have the correct event 
>> offset. (probably my fault when adding UIBlock/callbacks)
>> * callbacks could crash if they were free'd before the script ran them,
>>   solved this by using weakrefs to the python function rather then the 
>> function its self in the buttons callback value.
>>   Also store a list these weakref's in the Draw module's C file that 
>> are removed when the callback function is deallocated by python
>>   (using pythons own weakref callback) - if the weakref is not in the 
>> weakref callback list then we know it has been deallocated and can 
>> report an error that it needs to be made global.
>>
>> Tested this to work in UIBlock and normal button drawing.
>>   Some other small cleanup also.
>>   
> It'd kindof be nice if callbacks would be forced global by the API.  I 
> did this a while back for pyconstraints (in fact I was going to send it 
> to you, but I've been excruciatingly tired the last week) and it seemed 
> to work pretty well.
> 
> I'll attach the raw relavent files I had.  Basically callbacks and 
> button objects are stored in a list attached per spacetype, and this 
> list is cleared before each draw event.  Also tooltips are stored in 
> button objects onw.  Unfortunately I'm way too tired to update it for 
> current svn (I have to keep up on GSoC), so um this might be less then 
> useful in its current state.
> 
> Joe

another solution could be fine, but I tried a few before finding this 
one to work, simply incref'ing the callback for the button would be 
best, but that wont work unless there is some way to DECREF if when the 
button is removed from the 'block' - and I dont think there is.

making the function cause the variable to be global by its inclusion as 
a callback might work but Id rather not do too much tricky stuff behind 
the scenes since it can be one of those things that confuses the heck 
out of scripters until they read the source.

An alternative could be to check somehow that its global, but Im 
guessing its still possible to get out of scope - say if the scripter 
does "del var" after a global definition.

- Cam


More information about the Bf-committers mailing list