From b6270982de57399a758fe95000243ddb21846a49 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sat, 5 Sep 2026 15:05:41 +0100 Subject: [PATCH] Only assign global m_DebugPy when initialisation is successful * Prevents use on other threads e.g. python status check while partially initialised. --- qrenderdoc/Code/pyrenderdoc/PythonContext.cpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index fece2c673..c25390203 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -757,16 +757,16 @@ void PythonContext::GlobalInit(PersistentConfig &config) Py_DecRef(str); } - m_DebugPy = PyImport_ImportModule("debugpy"); + PyObject *debugpy = PyImport_ImportModule("debugpy"); - if(!m_DebugPy) + if(!debugpy) { qCritical() << "Failed to import debugpy"; HandleException(NULL); } else { - PyObject *configure = PyObject_SafeGetAttrString(m_DebugPy, "configure"); + PyObject *configure = PyObject_SafeGetAttrString(debugpy, "configure"); // don't let debugpy create a subprocess, for obvious reasons if(configure) @@ -779,8 +779,8 @@ void PythonContext::GlobalInit(PersistentConfig &config) { qCritical() << "Failed calling debugpy.configure"; HandleException(NULL); - Py_XDECREF(m_DebugPy); - m_DebugPy = NULL; + Py_XDECREF(debugpy); + debugpy = NULL; } Py_XDECREF(ret); @@ -793,9 +793,9 @@ void PythonContext::GlobalInit(PersistentConfig &config) Py_XDECREF(configure); - if(m_DebugPy) + if(debugpy) { - PyObject *listen = PyObject_SafeGetAttrString(m_DebugPy, "listen"); + PyObject *listen = PyObject_SafeGetAttrString(debugpy, "listen"); if(listen) { @@ -810,8 +810,12 @@ void PythonContext::GlobalInit(PersistentConfig &config) { qCritical() << "Failed calling debugpy.listen"; HandleException(NULL); - Py_XDECREF(m_DebugPy); - m_DebugPy = NULL; + Py_XDECREF(debugpy); + debugpy = NULL; + } + else + { + m_DebugPy = debugpy; } Py_XDECREF(ret);