Bugfix: in the game engine, errors in a particular python script caused

somewhat random crashes, which I think was caused by the error print
using python objects that were freed too soon. Now it frees the dictionary
after the print.
This commit is contained in:
2008-08-13 10:19:47 +00:00
parent 7af0643df7
commit d60025e95f

View File

@@ -273,36 +273,16 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
* break it by hand, then DECREF (which in this case * break it by hand, then DECREF (which in this case
* should always ensure excdict is cleared). * should always ensure excdict is cleared).
*/ */
/* PyObject *excdict= myPyDict_Copy(m_pythondictionary);
struct _object* resultobj = PyEval_EvalCode((PyCodeObject*)m_bytecode,
excdict,
excdict
);
PyDict_Clear(excdict);
Py_DECREF(excdict);*/
#if 1
PyObject *excdict= PyDict_Copy(m_pythondictionary); PyObject *excdict= PyDict_Copy(m_pythondictionary);
PyObject* resultobj = PyEval_EvalCode((PyCodeObject*)m_bytecode, PyObject* resultobj = PyEval_EvalCode((PyCodeObject*)m_bytecode,
excdict, excdict, excdict);
excdict
);
PyDict_Clear(excdict);
Py_DECREF(excdict);
#else
PyObject* resultobj = PyEval_EvalCode((PyCodeObject*)m_bytecode,
m_pythondictionary,
m_pythondictionary
);
#endif
if (resultobj) if (resultobj)
{ {
Py_DECREF(resultobj); Py_DECREF(resultobj);
} else }
else
{ {
// something is wrong, tell the user what went wrong // something is wrong, tell the user what went wrong
printf("PYTHON SCRIPT ERROR:\n"); printf("PYTHON SCRIPT ERROR:\n");
@@ -310,6 +290,11 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
//PyRun_SimpleString(m_scriptText.Ptr()); //PyRun_SimpleString(m_scriptText.Ptr());
} }
// clear after PyErrPrint - seems it can be using
// something in this dictionary and crash?
PyDict_Clear(excdict);
Py_DECREF(excdict);
m_sCurrentController = NULL; m_sCurrentController = NULL;
} }