From 0726f206947c230d06b428b5e158464bd196492f Mon Sep 17 00:00:00 2001 From: Jon Jenssen Date: Thu, 30 Apr 2026 16:33:04 +0200 Subject: [PATCH] Protect flattening code against polylines with a single point --- .../Intersections/RivSectionFlattener.cpp | 11 ++++++-- .../RimExtrudedCurveIntersection.cpp | 25 +++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/ApplicationLibCode/ModelVisualization/Intersections/RivSectionFlattener.cpp b/ApplicationLibCode/ModelVisualization/Intersections/RivSectionFlattener.cpp index 6e86683542..686ef9aa5b 100644 --- a/ApplicationLibCode/ModelVisualization/Intersections/RivSectionFlattener.cpp +++ b/ApplicationLibCode/ModelVisualization/Intersections/RivSectionFlattener.cpp @@ -55,8 +55,15 @@ std::vector RivSectionFlattener::calculateFlatteningCSsForPolyline( cvf::Vec3d* endOffset ) { CVF_ASSERT( endOffset ); - size_t pointCount = polyLine.size(); - CVF_ASSERT( pointCount > 1 ); + const size_t pointCount = polyLine.size(); + if ( pointCount == 0 ) return {}; + // If only one point, return identity matrix, as we can't calculate a direction + if ( pointCount == 1 ) + { + // trigger assert in debug builds, as this should not happen, but return something valid in release builds + CVF_TIGHT_ASSERT( false ); + return { cvf::Mat4d() }; + } std::vector segmentTransforms; segmentTransforms.reserve( pointCount ); diff --git a/ApplicationLibCode/ProjectDataModel/Intersections/RimExtrudedCurveIntersection.cpp b/ApplicationLibCode/ProjectDataModel/Intersections/RimExtrudedCurveIntersection.cpp index 5200554469..480720ada4 100644 --- a/ApplicationLibCode/ProjectDataModel/Intersections/RimExtrudedCurveIntersection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Intersections/RimExtrudedCurveIntersection.cpp @@ -848,6 +848,16 @@ std::vector> RimExtrudedCurveIntersection::polyLines( cv lines.push_back( m_twoAzimuthPoints ); } + // remove all line segments with less than 2 points + std::vector> filteredLines; + for ( auto l : lines ) + { + if ( l.size() > 1 ) + { + filteredLines.push_back( l ); + } + } + if ( type() == CrossSectionEnum::CS_WELL_PATH || type() == CrossSectionEnum::CS_SIMULATION_WELL ) { if ( type() == CrossSectionEnum::CS_SIMULATION_WELL && m_simulationWell() ) @@ -856,31 +866,32 @@ std::vector> RimExtrudedCurveIntersection::polyLines( cv m_simulationWell->wellHeadTopBottomPosition( -1, &top, &bottom ); - for ( std::vector& polyLine : lines ) + for ( std::vector& polyLine : filteredLines ) { polyLine.insert( polyLine.begin(), top ); } } - for ( std::vector& polyLine : lines ) + for ( std::vector& polyLine : filteredLines ) { addExtents( polyLine ); } - if ( flattenedPolylineStartPoint && !lines.empty() && lines[0].size() > 1 ) + if ( flattenedPolylineStartPoint && !filteredLines.empty() && filteredLines[0].size() > 1 ) { ( *flattenedPolylineStartPoint )[0] = horizontalProjectedLengthAlongWellPathToClipPoint - m_extentLength; - ( *flattenedPolylineStartPoint )[2] = lines[0][1].z(); // Depth of first point in first polyline + ( *flattenedPolylineStartPoint )[2] = filteredLines[0][1].z(); // Depth of first point in first polyline } } else { - if ( flattenedPolylineStartPoint && !lines.empty() && !( lines[0] ).empty() ) + if ( flattenedPolylineStartPoint && !filteredLines.empty() && !( filteredLines[0] ).empty() ) { - ( *flattenedPolylineStartPoint )[2] = lines[0][0].z(); // Depth of first point in first polyline + ( *flattenedPolylineStartPoint )[2] = filteredLines[0][0].z(); // Depth of first point in first polyline } } - return lines; + + return filteredLines; } //--------------------------------------------------------------------------------------------------