From 282c44ead1c4e8204f7e700d3a4bf0d22ac5373b Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Sat, 24 Feb 2024 00:18:31 +0100 Subject: [PATCH] Gui: PythonWrapper: Do not steal reference Foreign Python objects needs to be passed as Py::Object(). Py::asObject() is stealing reference and object might be garbage collected even before dereferenced. Problem didn't show in the original code because methods Py::asObject() was used in were never called. Fixes: 26babf4d3674 (Gui: Consolidate Python -> Qt class conversion) --- src/Gui/PythonWrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gui/PythonWrapper.cpp b/src/Gui/PythonWrapper.cpp index 6426195640..e2128e3ec0 100644 --- a/src/Gui/PythonWrapper.cpp +++ b/src/Gui/PythonWrapper.cpp @@ -472,7 +472,7 @@ qttype* qt_getCppType(PyObject* pyobj) Py::Callable func = mainmod.getDict().getItem("getCppPointer"); Py::Tuple arguments(1); - arguments[0] = Py::asObject(pyobj); // PySide pointer + arguments[0] = Py::Object(pyobj); // PySide pointer Py::Tuple result(func.apply(arguments)); return reinterpret_cast(PyLong_AsVoidPtr(result[0].ptr())); }