fix: crash in Measure tool when a plain edge is the first selection (#14538)

* fix: crash in Measure tool when a plain edge is the first selection

The SPHERE_2 gripper raycaster called get_feature_offset() on
.first.feature instead of .second.feature (copy-pasted from the SPHERE_1
block). Plain planar-border edges store no extra point, so the Edge
branch dereferenced an empty optional behind a release-stripped assert,
aborting on Flatpak and undefined behavior elsewhere.

Point the SPHERE_2 raycaster at .second.feature and fall the Edge branch
back to the edge midpoint.

Fixes #14018
This commit is contained in:
raistlin7447
2026-07-02 22:29:28 -05:00
committed by GitHub
parent 036bd7bcec
commit adc8763099

View File

@@ -91,9 +91,14 @@ Vec3d GLGizmoMeasure::get_feature_offset(const Measure::SurfaceFeature &feature)
} }
case Measure::SurfaceFeatureType::Edge: case Measure::SurfaceFeatureType::Edge:
{ {
std::optional<Vec3d> p = feature.get_extra_point(); // Only polygon edges store an extra point (the polygon centre); plain edges have none.
assert(p.has_value()); const std::optional<Vec3d> extra = feature.get_extra_point();
ret = *p; if (extra.has_value())
ret = *extra;
else {
const auto [pt1, pt2] = feature.get_edge();
ret = 0.5 * (pt1 + pt2);
}
break; break;
} }
case Measure::SurfaceFeatureType::Point: case Measure::SurfaceFeatureType::Point:
@@ -1065,7 +1070,7 @@ void GLGizmoMeasure::on_render()
if (requires_raycaster_update) { if (requires_raycaster_update) {
if (m_gripper_id_raycast_map.find(GripperType::SPHERE_2) != m_gripper_id_raycast_map.end()) { if (m_gripper_id_raycast_map.find(GripperType::SPHERE_2) != m_gripper_id_raycast_map.end()) {
m_gripper_id_raycast_map[GripperType::SPHERE_2]->set_transform(Geometry::translation_transform(get_feature_offset(*m_selected_features.first.feature)) * m_gripper_id_raycast_map[GripperType::SPHERE_2]->set_transform(Geometry::translation_transform(get_feature_offset(*m_selected_features.second.feature)) *
Geometry::scale_transform(inv_zoom)); Geometry::scale_transform(inv_zoom));
} }
} }