Don't use sys.stdout to find global handle

* Instead store sys._renderdoc_internal that won't be overwritten.
This commit is contained in:
baldurk
2026-03-10 17:05:22 +00:00
parent 6e3a0201a8
commit a72ea34c6c
@@ -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;