Skip to content

Commit

Permalink
PD: fix crash in TaskRevolutionParameters::fillAxisCombo
Browse files Browse the repository at this point in the history
* Replacing the static_cast with a dynamic_cast in 2aa232b 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
  • Loading branch information
wwmayer committed Jan 2, 2023
1 parent fe49964 commit f882719
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp
Expand Up @@ -114,12 +114,12 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill)
ui->axis->clear();
axesInList.clear();

//add sketch axes
auto *pcFeat = dynamic_cast<PartDesign::ProfileBased*>(vp->getObject());
if (!pcFeat)
throw Base::TypeError("The object is not ProfileBased.");
auto *pcSketch = static_cast<Part::Part2DObject*>(pcFeat->Profile.getValue());
if (pcSketch){

//add sketch axes
if (auto *pcSketch = dynamic_cast<Part::Part2DObject*>(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++) {
Expand All @@ -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"));
Expand Down

0 comments on commit f882719

Please sign in to comment.