Measure: Fix crash when removing referenced element
Also improve error messages Fixes #16183
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user