From f8827198ee137781dd357e68b67091915e0c01b2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 2 Jan 2023 09:49:27 +0100 Subject: [PATCH] PD: fix crash in TaskRevolutionParameters::fillAxisCombo * Replacing the static_cast with a dynamic_cast in 2aa232bef9 is a regression because it cannot be guaranteed that the linked object is a sketch. In fact it can also be a shape binder which is explicitly allowed. Forum: https://forum.freecadweb.org/viewtopic.php?f=19&t=74939 * Move initialization of some variables into the if-statement --- src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index ff3baf993e15..a9550a46a086 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -114,12 +114,12 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) ui->axis->clear(); axesInList.clear(); - //add sketch axes auto *pcFeat = dynamic_cast(vp->getObject()); if (!pcFeat) throw Base::TypeError("The object is not ProfileBased."); - auto *pcSketch = static_cast(pcFeat->Profile.getValue()); - if (pcSketch){ + + //add sketch axes + if (auto *pcSketch = dynamic_cast(pcFeat->Profile.getValue())) { addAxisToCombo(pcSketch, "V_Axis", QObject::tr("Vertical sketch axis")); addAxisToCombo(pcSketch, "H_Axis", QObject::tr("Horizontal sketch axis")); for (int i=0; i < pcSketch->getAxisCount(); i++) { @@ -130,9 +130,8 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) } } - //add part axes - PartDesign::Body * body = PartDesign::Body::findBodyOf ( pcFeat ); - if (body) { + //add origin axes + if (PartDesign::Body * body = PartDesign::Body::findBodyOf(pcFeat)) { try { App::Origin* orig = body->getOrigin(); addAxisToCombo(orig->getX(), std::string(), tr("Base X axis"));