From 4d51d1d0b1c2cd33cd443d477c60eb575fc0e52f Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 27 Mar 2022 11:32:33 +0200 Subject: [PATCH] FEM: [skip ci] fix possible crash in setupFilter() function --- src/Mod/Fem/Gui/Command.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index bef0e624d8..d2794e9404 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -1165,14 +1165,14 @@ void setupFilter(Gui::Command* cmd, std::string Name) { // at first we must determine the pipeline of the selection object (which can be a pipeline itself) bool selectionIsPipeline = false; - Fem::FemPostPipeline* pipeline; + Fem::FemPostPipeline* pipeline = nullptr; if (selObject->getTypeId() == Base::Type::fromName("Fem::FemPostPipeline")) { pipeline = static_cast(selObject); selectionIsPipeline = true; } else { auto parents = selObject->getInList(); - if (parents.size()) { + if (!parents.empty()) { for (auto parentObject : parents) { if (parentObject->getTypeId() == Base::Type::fromName("Fem::FemPostPipeline")) { pipeline = static_cast(parentObject); @@ -1181,6 +1181,13 @@ void setupFilter(Gui::Command* cmd, std::string Name) { } } + if (!pipeline) { + QMessageBox::warning(Gui::getMainWindow(), + qApp->translate("setupFilter", "Error: no post processing object selected."), + qApp->translate("setupFilter", "The filter could not be set up.")); + return; + } + // create the object and add it to the pipeline cmd->openCommand(QT_TRANSLATE_NOOP("Command", "Create filter")); cmd->doCommand(Gui::Command::Doc, "App.activeDocument().addObject('Fem::FemPost%sFilter','%s')", Name.c_str(), FeatName.c_str());