Fix #141339: Mantaflow: Clear Python errors when grids aren't available
Adding a Flow to a Mantaflow domain could sometimes cause a crash. This was because the grids are allocated lazily, and as such, getting them through `PyObject_GetAttrString` will fail when they are not yet available. As the resulting Python errors were not cleared, Python could be left in a bad state, leading to crashes. This is avoided by clearing these errors before returning from `callPythonFunction` when such an error is raised. Ref !141364
This commit is contained in:
committed by
Campbell Barton
parent
954dbedc57
commit
94f4df8ec4
@@ -2029,6 +2029,7 @@ static PyObject *callPythonFunction(string varName, string functionName, bool is
|
||||
|
||||
var = PyObject_GetAttrString(manta_main_module, varName.c_str());
|
||||
if (!var) {
|
||||
PyErr_Clear();
|
||||
PyGILState_Release(gilstate);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -2037,12 +2038,17 @@ static PyObject *callPythonFunction(string varName, string functionName, bool is
|
||||
|
||||
Py_DECREF(var);
|
||||
if (!func) {
|
||||
PyErr_Clear();
|
||||
PyGILState_Release(gilstate);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!isAttribute) {
|
||||
returnedValue = PyObject_CallObject(func, nullptr);
|
||||
if (returnedValue == nullptr) {
|
||||
/* Print any unexpected errors, also clear them. */
|
||||
PyErr_Print();
|
||||
}
|
||||
Py_DECREF(func);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user