Measure: Fix crash when removing referenced element

Also improve error messages
Fixes #16183
This commit is contained in:
hlorus
2024-09-02 11:20:21 +02:00
committed by WandererFan
parent ec3adf5fa0
commit 62a44a94f6
9 changed files with 27 additions and 36 deletions

View File

@@ -97,12 +97,6 @@ void MeasureLength::parseSelection(const App::MeasureSelection& selection)
App::DocumentObjectExecReturn* MeasureLength::execute()
{
recalculateLength();
return DocumentObject::StdReturn;
}
void MeasureLength::recalculateLength()
{
const std::vector<App::DocumentObject*>& objects = Elements.getValues();
const std::vector<std::string>& subElements = Elements.getSubValues();
@@ -115,7 +109,7 @@ void MeasureLength::recalculateLength()
App::SubObjectT subject {objects.at(i), subElements.at(i).c_str()};
auto info = getMeasureInfo(subject);
if (!info || !info->valid) {
continue;
return new App::DocumentObjectExecReturn("Cannot calculate length");
}
auto lengthInfo = std::dynamic_pointer_cast<Part::MeasureLengthInfo>(info);
@@ -123,8 +117,10 @@ void MeasureLength::recalculateLength()
}
Length.setValue(result);
return DocumentObject::StdReturn;
}
void MeasureLength::onChanged(const App::Property* prop)
{
if (isRestoring() || isRemoving()) {
@@ -132,7 +128,8 @@ void MeasureLength::onChanged(const App::Property* prop)
}
if (prop == &Elements) {
recalculateLength();
auto ret = recompute();
delete ret;
}
MeasureBase::onChanged(prop);