diff options
author | Campbell Barton <campbell@blender.org> | 2022-06-24 16:28:19 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-06-24 16:28:55 +0300 |
commit | ad8add5f0cbe1b5abb85a6cf510e52b66de273e9 (patch) | |
tree | 62b652fba9ab7da15bb41dc6254cf8a8b02e2dfd /extern | |
parent | 2580d2bab50f399f101095a197301229614b1d48 (diff) |
Fix T98427: Crash adding quick effects smoke from Python
Manta flow used the `__main__` namespace which it was executed in,
this caused a bug when calculating fluid from Python, which clears
it's `__main__` name-space after execution.
This caused Manta-flows name space to be cleared too.
Resolve this by creating a separate name-space for manta-flow.
Reviewed by: SonnyCampbell_Unity
Ref D15269
Diffstat (limited to 'extern')
-rw-r--r-- | extern/mantaflow/helper/pwrapper/registry.cpp | 18 | ||||
-rw-r--r-- | extern/mantaflow/helper/pwrapper/registry.h | 2 |
2 files changed, 14 insertions, 6 deletions
diff --git a/extern/mantaflow/helper/pwrapper/registry.cpp b/extern/mantaflow/helper/pwrapper/registry.cpp index 5196c0409f8..b20651f3baa 100644 --- a/extern/mantaflow/helper/pwrapper/registry.cpp +++ b/extern/mantaflow/helper/pwrapper/registry.cpp @@ -115,7 +115,7 @@ class WrapperRegistry { void construct(const std::string &scriptname, const vector<string> &args); void cleanup(); void renameObjects(); - void runPreInit(); + void runPreInit(PyObject *name_space); PyObject *initModule(); ClassData *lookup(const std::string &name); bool canConvert(ClassData *from, ClassData *to); @@ -505,7 +505,7 @@ void WrapperRegistry::addConstants(PyObject *module) } } -void WrapperRegistry::runPreInit() +void WrapperRegistry::runPreInit(PyObject *name_space) { // add python directories to path PyObject *sys_path = PySys_GetObject((char *)"path"); @@ -518,7 +518,15 @@ void WrapperRegistry::runPreInit() } if (!mCode.empty()) { mCode = "from manta import *\n" + mCode; - PyRun_SimpleString(mCode.c_str()); + PyObject *return_value = PyRun_String(mCode.c_str(), Py_file_input, name_space, name_space); + if (return_value == nullptr) { + if (PyErr_Occurred()) { + PyErr_Print(); + } + } + else { + Py_DECREF(return_value); + } } } @@ -698,11 +706,11 @@ PyObject *WrapperRegistry::initModule() //****************************************************** // Register members and exposed functions -void setup(const std::string &filename, const std::vector<std::string> &args) +void setup(const std::string &filename, const std::vector<std::string> &args, PyObject *name_space) { WrapperRegistry::instance().construct(filename, args); Py_Initialize(); - WrapperRegistry::instance().runPreInit(); + WrapperRegistry::instance().runPreInit(name_space); } void finalize() diff --git a/extern/mantaflow/helper/pwrapper/registry.h b/extern/mantaflow/helper/pwrapper/registry.h index d9d2bbb624b..aa63383515f 100644 --- a/extern/mantaflow/helper/pwrapper/registry.h +++ b/extern/mantaflow/helper/pwrapper/registry.h @@ -48,7 +48,7 @@ template<class T> struct Namify { namespace Pb { // internal registry access -void setup(const std::string &filename, const std::vector<std::string> &args); +void setup(const std::string &filename, const std::vector<std::string> &args, PyObject *name_space); void finalize(); bool canConvert(PyObject *obj, const std::string &to); Manta::PbClass *objFromPy(PyObject *obj); |