From d22da5e297be65952be2816840ec81245920ff3b Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 18 Apr 2017 11:14:04 +0100 Subject: [PATCH] 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. --- qrenderdoc/Code/pyrenderdoc/PythonContext.cpp | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index b61793650..b381ab68c 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -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; } }