From 721e37d888a92bf7fcdb63a1cecf5b140f3611b9 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 18 Aug 2018 16:01:55 +0200 Subject: [PATCH] fix several reference counting bugs --- src/Gui/SoFCSelectionAction.cpp | 12 ++++++++++++ src/Gui/View3DInventorViewer.cpp | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Gui/SoFCSelectionAction.cpp b/src/Gui/SoFCSelectionAction.cpp index c00a22e29e..fad3158e8c 100644 --- a/src/Gui/SoFCSelectionAction.cpp +++ b/src/Gui/SoFCSelectionAction.cpp @@ -1159,6 +1159,10 @@ SoBoxSelectionRenderAction::constructorCommon(void) SoBoxSelectionRenderAction::~SoBoxSelectionRenderAction(void) { + // clear highlighting node + if (PRIVATE(this)->highlightPath) { + PRIVATE(this)->highlightPath->unref(); + } PRIVATE(this)->postprocpath->unref(); PRIVATE(this)->localRoot->unref(); @@ -1218,6 +1222,10 @@ SoBoxSelectionRenderAction::apply(SoNode * node) if (shapepath) { SoPathList list; list.append(shapepath); + // clear old highlighting node if still active + if (PRIVATE(this)->highlightPath) { + PRIVATE(this)->highlightPath->unref(); + } PRIVATE(this)->highlightPath = path; PRIVATE(this)->highlightPath->ref(); this->drawBoxes(path, &list); @@ -1262,6 +1270,10 @@ SoBoxSelectionRenderAction::apply(SoPath * path) if (shapepath) { SoPathList list; list.append(shapepath); + // clear old highlighting node if still active + if (PRIVATE(this)->highlightPath) { + PRIVATE(this)->highlightPath->unref(); + } PRIVATE(this)->highlightPath = path; PRIVATE(this)->highlightPath->ref(); this->drawBoxes(path, &list); diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index dc2a4d4115..d1d4f5ae43 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -578,6 +578,14 @@ View3DInventorViewer::~View3DInventorViewer() static_cast(_viewerPy)->_viewer = 0; Py_DECREF(_viewerPy); } + + // In the init() function we have overridden the default SoGLRenderAction with our + // own instance of SoBoxSelectionRenderAction and SoRenderManager destroyed the default. + // But it does this only once so that now we have to explicitly destroy our instance in + // order to free the memory. + SoGLRenderAction* glAction = this->getSoRenderManager()->getGLRenderAction(); + this->getSoRenderManager()->setGLRenderAction(nullptr); + delete glAction; } void View3DInventorViewer::aboutToDestroyGLContext()