Step up python stack until we find our globals, or run out of stack

* In python globals aren't really global, they're just module-level
  variables. So to find our _renderdoc_internal we have to potentailly
  walk the stack if we're inside another module until we get to the
  globals dict we set up.
This commit is contained in:
baldurk
2017-04-18 11:14:04 +01:00
parent ab41f1ec6a
commit d22da5e297
+16 -6
View File
@@ -635,13 +635,23 @@ PyObject *PythonContext::outstream_write(PyObject *self, PyObject *args)
// contexts. So look up the global variable that stores the context
if(context == NULL)
{
PyObject *globals = PyEval_GetGlobals();
if(globals)
_frame *frame = PyEval_GetFrame();
while(frame)
{
OutputRedirector *global =
(OutputRedirector *)PyDict_GetItemString(globals, "_renderdoc_internal");
if(global)
context = global->context;
PyObject *globals = frame->f_globals;
if(globals)
{
OutputRedirector *global =
(OutputRedirector *)PyDict_GetItemString(globals, "_renderdoc_internal");
if(global)
context = global->context;
}
if(context)
break;
frame = frame->f_back;
}
}