* Fixed crash on file image selectors:
The global python dict can't be cleaned before the callbacks are executed.
This commit is contained in:
@@ -222,7 +222,7 @@ struct _object *BPY_txt_do_python(struct SpaceText* st)
|
|||||||
{
|
{
|
||||||
PyObject *dict, *ret;
|
PyObject *dict, *ret;
|
||||||
|
|
||||||
printf ("In BPY_txt_do_python\n");
|
printf ("\nIn BPY_txt_do_python\n");
|
||||||
|
|
||||||
if (!st->text) return NULL;
|
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,
|
* the script with a clean global dictionary or should keep the current one,
|
||||||
* possibly already "polluted" by other calls to the Python Interpreter.
|
* 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
|
* 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) {
|
if (EXPP_releaseGlobalDict) {
|
||||||
printf("Using a clean Global Dictionary.\n");
|
printf("Using a clean Global Dictionary.\n");
|
||||||
|
@@ -36,6 +36,10 @@
|
|||||||
|
|
||||||
#include "Draw.h"
|
#include "Draw.h"
|
||||||
|
|
||||||
|
/* declared in ../BPY_extern.h,
|
||||||
|
* used to control global dictionary persistence: */
|
||||||
|
extern short EXPP_releaseGlobalDict;
|
||||||
|
|
||||||
static void Button_dealloc(PyObject *self)
|
static void Button_dealloc(PyObject *self)
|
||||||
{
|
{
|
||||||
Button *but = (Button*)self;
|
Button *but = (Button*)self;
|
||||||
@@ -192,21 +196,21 @@ int BPY_spacetext_is_pywin(SpaceText *st)
|
|||||||
static PyObject *Method_Exit (PyObject *self, PyObject *args)
|
static PyObject *Method_Exit (PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
SpaceText *st= curarea->spacedata.first;
|
SpaceText *st= curarea->spacedata.first;
|
||||||
#ifdef CLEAR_NAMESPACE
|
|
||||||
PyObject *d;
|
|
||||||
#endif
|
|
||||||
if (!PyArg_ParseTuple(args, ""))
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||||
"expected empty argument list");
|
"expected empty argument list");
|
||||||
|
|
||||||
exit_pydraw(st);
|
exit_pydraw(st);
|
||||||
#ifdef CLEAR_NAMESPACE
|
|
||||||
d = st->py_globaldict; /* The current window's global namespace dictionary */
|
if (EXPP_releaseGlobalDict) {
|
||||||
if (d) {
|
PyObject *d = st->py_globaldict;
|
||||||
PyDict_Clear(d);
|
/* d is the current window's global namespace dictionary */
|
||||||
Py_DECREF(d); /* release dictionary */
|
if (d) {
|
||||||
|
PyDict_Clear(d);
|
||||||
|
Py_DECREF(d); /* release dictionary */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return EXPP_incr_ret (Py_None);
|
return EXPP_incr_ret (Py_None);
|
||||||
}
|
}
|
||||||
|
@@ -123,18 +123,26 @@ static PyObject *M_Window_QRedrawAll(PyObject *self, PyObject *args)
|
|||||||
static void getSelectedFile(char *name)
|
static void getSelectedFile(char *name)
|
||||||
{
|
{
|
||||||
if (EXPP_FS_PyCallback) {
|
if (EXPP_FS_PyCallback) {
|
||||||
|
SpaceText *st= curarea->spacedata.first;
|
||||||
|
|
||||||
PyObject_CallFunction((PyObject *)EXPP_FS_PyCallback, "s", name);
|
PyObject_CallFunction((PyObject *)EXPP_FS_PyCallback, "s", name);
|
||||||
EXPP_FS_PyCallback = NULL;
|
|
||||||
|
EXPP_FS_PyCallback = NULL;
|
||||||
|
st->flags &= ST_CLEAR_NAMESPACE; /* free global dictionary */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args)
|
static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *title = "SELECT FILE";
|
char *title = "SELECT FILE";
|
||||||
|
SpaceText *st = curarea->spacedata.first;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O!|s",
|
if (!PyArg_ParseTuple(args, "O!|s",
|
||||||
&PyFunction_Type, &EXPP_FS_PyCallback, &title))
|
&PyFunction_Type, &EXPP_FS_PyCallback, &title))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||||
"\nexpected a callback function (and optionally a string) as argument(s)"));
|
"\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);
|
activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile);
|
||||||
|
|
||||||
@@ -145,10 +153,14 @@ static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args)
|
|||||||
static PyObject *M_Window_ImageSelector(PyObject *self, PyObject *args)
|
static PyObject *M_Window_ImageSelector(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *title = "SELECT IMAGE";
|
char *title = "SELECT IMAGE";
|
||||||
|
SpaceText *st = curarea->spacedata.first;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O!|s",
|
if (!PyArg_ParseTuple(args, "O!|s",
|
||||||
&PyFunction_Type, &EXPP_FS_PyCallback, &title))
|
&PyFunction_Type, &EXPP_FS_PyCallback, &title))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||||
"\nexpected a callback function (and optionally a string) as argument(s)"));
|
"\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);
|
activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user