[Bf-python] Memory bug in Bpy api

Willian Padovani Germano wgermano at superig.com.br
Wed Jan 18 15:50:54 CET 2006


Bobby Parker wrote:
> Can you suggest a better method of developing a script in such a fashion 
> that several people can work on components of it?

I don't know the details of how your script should work, so please point 
any problem with my suggestions.

Blender.Run() can be used to execute another script. If your data is 
kept in a place accessible to all scripts (*), you can open each 
component as a separate script, with its own gui, called with 
Blender.Run() from the master script.

(*) aka anywhere outside that script's global dict. The Registry dict 
would be the fastest, but Blender texts, external files or an external 
database are other possibilities, depending on the type and amount of 
data you need.

If one script changes data used by others or sets state info that other 
scripts need, just be sure to get / check this data in the draw 
callbacks, because these all always executed when you move to a script's 
gui and thus you will get the current value of the needed data.

So you can divide your script: one dealing with the data (and a place 
where the data is stored), module(s) with common functions and "light" 
ones to display the guis.

> Also, I'm not following your above indicated method, rather I'm doing 
> import from math.* since the Register() function doesn't appear to be 
> happy with callbacks stored in a module (as in ShaderEditorGUI.draw()), 
> since that loads the functions/variables I need into the current 
> namespaces( at least I think/hope that's what's happening, and results 
> seem to bear me out).

Saving a function is not enough, you'd also need to store everything it 
used (which can be cumbersome for methods, complex functions, etc), or 
some references are lost. The simplest is to only store very basic data 
(numbers, strings) in the Registry, not Blender objects, functions, etc.

Yep, I understood math was only an example Toni used in his email and 
used it as an example, too (sorry if I "sounded" harsh or anything).

There are multiple ways to create the data for shader parameters and 
keep it around to create guis dynamically, you know. I didn't test your 
code, but if you're saving created Blender buttons, that might cause the 
crashes (String buttons come to mind). Try to save only the info needed 
to recreate the buttons.

Feel free to keep discussing, we all benefit from it (and we enjoy 
Python :) ).

--
Willian



More information about the Bf-python mailing list