Merge branch 'blender-v2.83-release'
This commit is contained in:
commit
0c1b1e734e
|
@ -552,31 +552,49 @@ MANTA::~MANTA()
|
|||
(void)result; // not needed in release
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a pointer to the __main__ module used by mantaflow. This is necessary, because sometimes
|
||||
* Blender will overwrite that module. That happens when e.g. scripts are executed in the text
|
||||
* editor.
|
||||
*
|
||||
* Mantaflow stores many variables in the globals() dict of the __main__ module. To be able to
|
||||
* access these variables, the same __main__ module has to be used every time.
|
||||
*
|
||||
* Unfortunately, we also depend on the fact that mantaflow dumps variables into this module using
|
||||
* PyRun_SimpleString. So we can't easily create a separate module without changing mantaflow.
|
||||
*/
|
||||
static PyObject *manta_main_module = nullptr;
|
||||
|
||||
bool MANTA::runPythonString(vector<string> commands)
|
||||
{
|
||||
int success = -1;
|
||||
bool success = true;
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
for (vector<string>::iterator it = commands.begin(); it != commands.end(); ++it) {
|
||||
string command = *it;
|
||||
|
||||
#ifdef WIN32
|
||||
// special treatment for windows when running python code
|
||||
size_t cmdLength = command.length();
|
||||
char *buffer = new char[cmdLength + 1];
|
||||
memcpy(buffer, command.data(), cmdLength);
|
||||
if (manta_main_module == nullptr) {
|
||||
manta_main_module = PyImport_ImportModule("__main__");
|
||||
}
|
||||
|
||||
buffer[cmdLength] = '\0';
|
||||
success = PyRun_SimpleString(buffer);
|
||||
delete[] buffer;
|
||||
#else
|
||||
success = PyRun_SimpleString(command.c_str());
|
||||
#endif
|
||||
for (vector<std::string>::iterator it = commands.begin(); it != commands.end(); ++it) {
|
||||
std::string command = *it;
|
||||
|
||||
PyObject *globals_dict = PyModule_GetDict(manta_main_module);
|
||||
PyObject *return_value = PyRun_String(
|
||||
command.c_str(), Py_file_input, globals_dict, globals_dict);
|
||||
|
||||
if (return_value == nullptr) {
|
||||
success = false;
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Py_DECREF(return_value);
|
||||
}
|
||||
}
|
||||
PyGILState_Release(gilstate);
|
||||
|
||||
/* PyRun_SimpleString returns 0 on success, -1 when an error occurred. */
|
||||
assert(success == 0);
|
||||
return (success != -1);
|
||||
assert(success);
|
||||
return success;
|
||||
}
|
||||
|
||||
void MANTA::initializeMantaflow()
|
||||
|
@ -1988,19 +2006,18 @@ static PyObject *callPythonFunction(string varName, string functionName, bool is
|
|||
}
|
||||
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
PyObject *main = nullptr, *var = nullptr, *func = nullptr, *returnedValue = nullptr;
|
||||
PyObject *var = nullptr, *func = nullptr, *returnedValue = nullptr;
|
||||
|
||||
/* Be sure to initialise Python before importing main. */
|
||||
/* Be sure to initialize Python before using it. */
|
||||
Py_Initialize();
|
||||
|
||||
// Get pyobject that holds result value
|
||||
main = PyImport_ImportModule("__main__");
|
||||
if (!main) {
|
||||
if (!manta_main_module) {
|
||||
PyGILState_Release(gilstate);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
var = PyObject_GetAttrString(main, varName.c_str());
|
||||
var = PyObject_GetAttrString(manta_main_module, varName.c_str());
|
||||
if (!var) {
|
||||
PyGILState_Release(gilstate);
|
||||
return nullptr;
|
||||
|
|
|
@ -267,7 +267,6 @@ DRWShadingGroup *workbench_image_setup_ex(WORKBENCH_PrivateData *wpd,
|
|||
}
|
||||
|
||||
if (tex == NULL) {
|
||||
printf("Image not found\n");
|
||||
tex = wpd->dummy_image_tx;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue