PD: fix crash in TaskRevolutionParameters::fillAxisCombo

* Replacing the static_cast with a dynamic_cast in 668adaacdf 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
This commit is contained in:
wmayer
2023-01-02 09:49:27 +01:00
parent a67f4fcb74
commit 05959a2beb

View File

@@ -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++) {
@@ -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"));