From 94f4df8ec4ad5937d4e69d8b1638444b5270b71e Mon Sep 17 00:00:00 2001 From: Jorn Visser Date: Thu, 3 Jul 2025 23:17:25 +0000 Subject: [PATCH] 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 --- intern/mantaflow/intern/MANTA_main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp index 0ef0e73927c..2217e45268b 100644 --- a/intern/mantaflow/intern/MANTA_main.cpp +++ b/intern/mantaflow/intern/MANTA_main.cpp @@ -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); }