From 466519f3c1cb05fb108d8dc3c2c1235c7bded78b Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 29 Dec 2023 08:22:14 +0800 Subject: [PATCH] Gui: fix crash on manual alignment Fixes #906 --- src/Gui/View3DInventorViewer.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index c322b482dbee..f4e77cbeef3d 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -339,17 +339,23 @@ class SpaceNavigatorDevice : public Quarter::InputDevice { template static ValueT _shadowParam(View3DInventor *view, const char *_name, const char *_docu, const ValueT &def, CallbackT cb) { + if (!view) + return def; return view->getProperty(_name, _docu, "Shadow", def, cb); } template static ValueT _shadowParam(View3DInventor *view, const char *_name, const char *_docu, const ValueT &def) { + if (!view) + return def; auto cb = [](PropT &){}; return view->getProperty(_name, _docu, "Shadow", def, cb); } template static void _shadowSetParam(View3DInventor *view, const char *_name, const ValueT &def) { + if (!view) + return; view->getProperty(_name, nullptr, "Shadow", def, [&def](PropT &prop) { Base::ObjectStatusLocker guard(App::Property::User3, &prop); @@ -359,11 +365,15 @@ static void _shadowSetParam(View3DInventor *view, const char *_name, const Value template static ValueT _hiddenLineParam(View3DInventor *view, const char *_name, const char *_docu, const ValueT &def, CallbackT cb) { + if (!view) + return def; return view->getProperty(_name, _docu, "HiddenLine", def, cb); } template static ValueT _hiddenLineParam(View3DInventor *view, const char *_name, const char *_docu, const ValueT &def) { + if (!view) + return def; auto cb = [](PropT &){}; return view->getProperty(_name, _docu, "HiddenLine", def, cb); } @@ -859,7 +869,7 @@ void View3DInventorViewer::setDocument(Gui::Document* pcDocument) selectionRoot->setDocument(pcDocument); inventorSelection->setDocument(pcDocument); - if(pcDocument) { + if(pcDocument && _pimpl->view) { const auto &sels = Selection().getSelection(pcDocument->getDocument()->getName(), ResolveMode::NoResolve); for(auto &sel : sels) { SelectionChanges Chng(SelectionChanges::ShowSelection, @@ -886,7 +896,7 @@ void View3DInventorViewer::setDocument(Gui::Document* pcDocument) void View3DInventorViewer::onViewPropertyChanged(const App::Property &prop) { - if(!prop.getName() || prop.testStatus(App::Property::User3)) + if(!prop.getName() || prop.testStatus(App::Property::User3) || !_pimpl->view) return; if (&prop == &_pimpl->view->ShowNaviCube) { @@ -1339,6 +1349,9 @@ void View3DInventorViewer::setOverrideMode(const std::string& mode) overrideMode = mode; applyOverrideMode(); + if (!_pimpl->view) + return; + if (!_pimpl->view->DrawStyle.testStatus(App::Property::User3)) { Base::ObjectStatusLocker guard( App::Property::User3, &_pimpl->view->DrawStyle); @@ -1384,6 +1397,9 @@ View3DInventorViewer::getHiddenLineConfig() const void View3DInventorViewer::Private::initHiddenLineConfig(bool activate) { + if (!view) + return; + auto bgColor = _hiddenLineParam( view, "Background", ViewParams::docHiddenLineBackground(), @@ -1519,6 +1535,9 @@ void View3DInventorViewer::Private::deactivateShadow() void View3DInventorViewer::Private::activateShadow() { + if (!view) + return; + owner->shading = true; App::Document *doc = owner->guiDocument?owner->guiDocument->getDocument():nullptr; @@ -2032,7 +2051,8 @@ void View3DInventorViewer::setRenderCache(int mode) void View3DInventorViewer::setEnabledNaviCube(bool on) { naviCubeEnabled = on; - _pimpl->view->ShowNaviCube.setValue(on); + if (_pimpl->view) + _pimpl->view->ShowNaviCube.setValue(on); } bool View3DInventorViewer::isEnabledNaviCube() const @@ -3873,7 +3893,7 @@ void View3DInventorViewer::Private::updateShadowGround(const SbBox3f &box) { App::Document *doc = owner->guiDocument?owner->guiDocument->getDocument():nullptr; - if (!pcShadowGroup || !doc) + if (!pcShadowGroup || !doc || !view) return; SbVec3f size = box.getSize(); @@ -5196,7 +5216,7 @@ void View3DInventorViewer::toggleShadowLightManip(int toggle) bool View3DInventorViewer::Private::toggleDragger(int toggle) { App::Document *doc = owner->guiDocument?owner->guiDocument->getDocument():nullptr; - if (!pcShadowGroup || !doc) + if (!pcShadowGroup || !doc || !view) return false; bool dirlight = pcShadowGroup->findChild(pcShadowDirectionalLight) >= 0;