From a72ea34c6cc0cb8c69532a3e923d8475e89fbd77 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 10 Mar 2026 17:05:22 +0000 Subject: [PATCH] Don't use sys.stdout to find global handle * Instead store sys._renderdoc_internal that won't be overwritten. --- qrenderdoc/Code/pyrenderdoc/PythonContext.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index 23007ccbd..77ae410e5 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -333,6 +333,7 @@ void PythonContext::GlobalInit() PyObject *redirector = PyObject_CallFunction((PyObject *)&OutputRedirectorType, noparams); PyObject_SetAttrString(sysobj, "stdout", redirector); + PyObject_SetAttrString(sysobj, "_renderdoc_internal", redirector); OutputRedirector *output = (OutputRedirector *)redirector; output->isStdError = 0; @@ -653,10 +654,10 @@ QString PythonContext::LoadExtension(ICaptureContext &ctx, const rdcstr &extensi PyObject *ext = NULL; - current_global_handle = PyObject_SafeGetAttrString(sysobj, "stdout"); + current_global_handle = PyObject_SafeGetAttrString(main_dict, "_renderdoc_internal"); if(!syspath) - qCritical() << "couldn't get sys.stdout"; + qCritical() << "couldn't get _renderdoc_internal"; QString typeStr; QString valueStr; @@ -1444,9 +1445,10 @@ extern "C" PyObject *GetCurrentGlobalHandle() PyObject *sys = PyImport_ImportModule("sys"); if(sys) { - PyObject *ret = PyObject_SafeGetAttrString(sys, "stdout"); + PyObject *ret = PyObject_SafeGetAttrString(sys, "_renderdoc_internal"); + Py_XDECREF(sys); - return ret; + Py_XDECREF(ret); } return NULL;