* Fixed crash on file image selectors:

The global python dict can't be cleaned before the callbacks are executed.
This commit is contained in:
2003-06-14 10:10:01 +00:00
parent c812a09ff3
commit 23b2a1be8f
3 changed files with 30 additions and 14 deletions

View File

@@ -222,7 +222,7 @@ struct _object *BPY_txt_do_python(struct SpaceText* st)
{
PyObject *dict, *ret;
printf ("In BPY_txt_do_python\n");
printf ("\nIn BPY_txt_do_python\n");
if (!st->text) return NULL;
@@ -230,7 +230,7 @@ struct _object *BPY_txt_do_python(struct SpaceText* st)
* the script with a clean global dictionary or should keep the current one,
* possibly already "polluted" by other calls to the Python Interpreter.
* The default is to use a clean one. To change this the script writer must
* call Blender.releaseGlobalDict(bool), with bool != 0, in the script */
* call Blender.releaseGlobalDict(bool), with bool == 0, in the script */
if (EXPP_releaseGlobalDict) {
printf("Using a clean Global Dictionary.\n");

View File

@@ -36,6 +36,10 @@
#include "Draw.h"
/* declared in ../BPY_extern.h,
* used to control global dictionary persistence: */
extern short EXPP_releaseGlobalDict;
static void Button_dealloc(PyObject *self)
{
Button *but = (Button*)self;
@@ -192,21 +196,21 @@ int BPY_spacetext_is_pywin(SpaceText *st)
static PyObject *Method_Exit (PyObject *self, PyObject *args)
{
SpaceText *st= curarea->spacedata.first;
#ifdef CLEAR_NAMESPACE
PyObject *d;
#endif
if (!PyArg_ParseTuple(args, ""))
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected empty argument list");
exit_pydraw(st);
#ifdef CLEAR_NAMESPACE
d = st->py_globaldict; /* The current window's global namespace dictionary */
if (EXPP_releaseGlobalDict) {
PyObject *d = st->py_globaldict;
/* d is the current window's global namespace dictionary */
if (d) {
PyDict_Clear(d);
Py_DECREF(d); /* release dictionary */
}
#endif
}
return EXPP_incr_ret (Py_None);
}

View File

@@ -123,19 +123,27 @@ static PyObject *M_Window_QRedrawAll(PyObject *self, PyObject *args)
static void getSelectedFile(char *name)
{
if (EXPP_FS_PyCallback) {
SpaceText *st= curarea->spacedata.first;
PyObject_CallFunction((PyObject *)EXPP_FS_PyCallback, "s", name);
EXPP_FS_PyCallback = NULL;
st->flags &= ST_CLEAR_NAMESPACE; /* free global dictionary */
}
}
static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args)
{
char *title = "SELECT FILE";
SpaceText *st = curarea->spacedata.first;
if (!PyArg_ParseTuple(args, "O!|s",
&PyFunction_Type, &EXPP_FS_PyCallback, &title))
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"\nexpected a callback function (and optionally a string) as argument(s)"));
st->flags &= ~ST_CLEAR_NAMESPACE; /* hold global dictionary */
activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile);
Py_INCREF(Py_None);
@@ -145,11 +153,15 @@ static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args)
static PyObject *M_Window_ImageSelector(PyObject *self, PyObject *args)
{
char *title = "SELECT IMAGE";
SpaceText *st = curarea->spacedata.first;
if (!PyArg_ParseTuple(args, "O!|s",
&PyFunction_Type, &EXPP_FS_PyCallback, &title))
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"\nexpected a callback function (and optionally a string) as argument(s)"));
st->flags &= ~ST_CLEAR_NAMESPACE; /* hold global dictionary */
activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile);
Py_INCREF(Py_None);