* Fixes segfault caused in the Object.getParent function.
Found by Jonathan Thambidurai * Fixes a scriptlink problem when a script is run using ALT-p. Found by Yann Vernier (LoneTech) * Prints unhandled exceptions. Should fix some memory leaks too. Fixed by Yann Verniet (LoneTech)
This commit is contained in:
@@ -240,6 +240,8 @@ struct _object *BPY_txt_do_python(struct SpaceText* st)
|
|||||||
else
|
else
|
||||||
dict = PyModule_GetDict(PyImport_AddModule("__main__"));
|
dict = PyModule_GetDict(PyImport_AddModule("__main__"));
|
||||||
|
|
||||||
|
clearScriptLinks ();
|
||||||
|
|
||||||
ret = RunPython (st->text, dict); /* Run the script */
|
ret = RunPython (st->text, dict); /* Run the script */
|
||||||
|
|
||||||
if (!ret) { /* Failed execution of the script */
|
if (!ret) { /* Failed execution of the script */
|
||||||
@@ -353,6 +355,7 @@ void BPY_do_pyscript(struct ID *id, short event)
|
|||||||
ScriptLink * scriptlink;
|
ScriptLink * scriptlink;
|
||||||
int index;
|
int index;
|
||||||
PyObject * dict;
|
PyObject * dict;
|
||||||
|
PyObject * ret;
|
||||||
|
|
||||||
printf ("In BPY_do_pyscript(id=%s, event=%d)\n",id->name, event);
|
printf ("In BPY_do_pyscript(id=%s, event=%d)\n",id->name, event);
|
||||||
|
|
||||||
@@ -368,8 +371,19 @@ void BPY_do_pyscript(struct ID *id, short event)
|
|||||||
(scriptlink->scripts[index] != NULL))
|
(scriptlink->scripts[index] != NULL))
|
||||||
{
|
{
|
||||||
dict = CreateGlobalDictionary();
|
dict = CreateGlobalDictionary();
|
||||||
RunPython ((Text*) scriptlink->scripts[index], dict);
|
ret = RunPython ((Text*) scriptlink->scripts[index], dict);
|
||||||
ReleaseGlobalDictionary (dict);
|
ReleaseGlobalDictionary (dict);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
/* Failed execution of the script */
|
||||||
|
BPY_Err_Handle ((Text*) scriptlink->scripts[index]);
|
||||||
|
BPY_end_python ();
|
||||||
|
BPY_start_python ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Py_DECREF (ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,6 +54,17 @@ void initBlenderApi2_2x (void)
|
|||||||
M_Blender_Init ();
|
M_Blender_Init ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearScriptLinks (void)
|
||||||
|
{
|
||||||
|
Py_INCREF (Py_False);
|
||||||
|
PyDict_SetItemString (g_blenderdict, "bylink", Py_False);
|
||||||
|
/* Old API meant link could be unset. Or even valid when bylink is false.
|
||||||
|
* This way, you can import it and check its value afterwards, ignoring
|
||||||
|
* bylink. */
|
||||||
|
Py_INCREF (Py_None);
|
||||||
|
PyDict_SetItemString (g_blenderdict, "link", Py_None);
|
||||||
|
}
|
||||||
|
|
||||||
ScriptLink * setScriptLinks(ID *id, short event)
|
ScriptLink * setScriptLinks(ID *id, short event)
|
||||||
{
|
{
|
||||||
ScriptLink * scriptlink;
|
ScriptLink * scriptlink;
|
||||||
|
@@ -32,4 +32,5 @@
|
|||||||
#include <DNA_ID.h>
|
#include <DNA_ID.h>
|
||||||
|
|
||||||
void initBlenderApi2_2x (void);
|
void initBlenderApi2_2x (void);
|
||||||
|
void clearScriptLinks (void);
|
||||||
ScriptLink * setScriptLinks(ID *id, short event);
|
ScriptLink * setScriptLinks(ID *id, short event);
|
||||||
|
@@ -400,6 +400,7 @@ PyObject *M_Object_Get(PyObject *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
blen_object = (C_Object*)PyObject_NEW (C_Object, &Object_Type);
|
blen_object = (C_Object*)PyObject_NEW (C_Object, &Object_Type);
|
||||||
blen_object->object = object;
|
blen_object->object = object;
|
||||||
|
blen_object->parent = NULL;
|
||||||
blen_object->data = NULL;
|
blen_object->data = NULL;
|
||||||
|
|
||||||
return ((PyObject*)blen_object);
|
return ((PyObject*)blen_object);
|
||||||
@@ -708,7 +709,10 @@ static PyObject *Object_getParent (C_Object *self)
|
|||||||
return ((PyObject*)self->parent);
|
return ((PyObject*)self->parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: what if self->object->parent==NULL? Should we return Py_None? */
|
if (self->object->parent == NULL)
|
||||||
|
{
|
||||||
|
return (EXPP_incr_ret (Py_None));
|
||||||
|
}
|
||||||
attr = M_ObjectCreatePyObject (self->object->parent);
|
attr = M_ObjectCreatePyObject (self->object->parent);
|
||||||
|
|
||||||
if (attr)
|
if (attr)
|
||||||
|
Reference in New Issue
Block a user