From c59155b97d51104a2e2b76a28a788484b18c5310 Mon Sep 17 00:00:00 2001 From: xtemp09 Date: Fri, 21 Apr 2023 15:42:05 +0700 Subject: [PATCH] Fixed segmentation fault in Path workbench Closes #6286. --- src/Mod/Path/PathSimulator/App/VolSim.cpp | 13 +++++-------- src/Mod/Path/PathSimulator/App/VolSim.h | 6 ++++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Mod/Path/PathSimulator/App/VolSim.cpp b/src/Mod/Path/PathSimulator/App/VolSim.cpp index 60bf0a31c0..6f5a457428 100644 --- a/src/Mod/Path/PathSimulator/App/VolSim.cpp +++ b/src/Mod/Path/PathSimulator/App/VolSim.cpp @@ -783,14 +783,11 @@ cSimTool::cSimTool(const TopoDS_Shape& toolShape, float res){ float cSimTool::GetToolProfileAt(float pos) // pos is -1..1 location along the radius of the tool (0 is center) { - try{ - float radPos = std::abs(pos) * radius; - toolShapePoint test; test.radiusPos = radPos; - auto it = std::lower_bound(m_toolShape.begin(), m_toolShape.end(), test, toolShapePoint::less_than()); - return it->heightPos; - }catch(...){ - return 0; - } + toolShapePoint test; + test.radiusPos = std::abs(pos) * radius; + + auto it = std::lower_bound(m_toolShape.begin(), m_toolShape.end(), test, toolShapePoint::less_than()); + return it != m_toolShape.end() ? it->heightPos : 0.0f; } bool cSimTool::isInside(const TopoDS_Shape& toolShape, Base::Vector3d pnt, float res) diff --git a/src/Mod/Path/PathSimulator/App/VolSim.h b/src/Mod/Path/PathSimulator/App/VolSim.h index 0a82fbb476..9fb45c2f74 100644 --- a/src/Mod/Path/PathSimulator/App/VolSim.h +++ b/src/Mod/Path/PathSimulator/App/VolSim.h @@ -107,8 +107,10 @@ public: float GetToolProfileAt(float pos); bool isInside(const TopoDS_Shape& toolShape, Base::Vector3d pnt, float res); - std::vector< toolShapePoint > m_toolShape; - float radius; +/* m_toolShape has to be populated with linearly increased + radiusPos to get the tool profile at given position */ + std::vector m_toolShape; + float radius; float length; };