From 05fb8451f07a95e22b470b6c1875f0072288ac91 Mon Sep 17 00:00:00 2001
From: Dongxu Li <dongxuli2011@gmail.com>
Date: Sat, 25 Jan 2025 08:00:11 -0500
Subject: [PATCH] Issue #2023: fixed a null pointer issue

(cherry picked from commit 2c3a939c254915468d2e57fa1d345338bda79a5b)
(cherry picked from commit c0e77247b39236a68cdbd396043482cd7afda513)
Upstream-Status: Backport
Signed-off-by: Ismael Luceno <ismael@sourcemage.org>
---
 librecad/src/lib/engine/rs_entitycontainer.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/librecad/src/lib/engine/rs_entitycontainer.cpp b/librecad/src/lib/engine/rs_entitycontainer.cpp
index dd36fc448d41..0cccf685734e 100644
--- a/librecad/src/lib/engine/rs_entitycontainer.cpp
+++ b/librecad/src/lib/engine/rs_entitycontainer.cpp
@@ -50,7 +50,7 @@
 namespace {
 
 // the tolerance used to check topology of contours in hatching
-constexpr double contourTolerance = 1e-8;
+constexpr double contourTolerance = 5e-7;
 
 // For validate hatch contours, whether an entity in the contour is a closed
 // loop itself
@@ -1188,7 +1188,7 @@ RS_Vector RS_EntityContainer::getNearestEndpoint(const RS_Vector& coord,
     for (RS_Entity* en: entities){
 
         if (en->isVisible()
-                && !en->getParent()->ignoredOnModification()
+                && (en->getParent()==nullptr || !en->getParent()->ignoredOnModification())
                 ){//no end point for Insert, text, Dim
             point = en->getNearestEndpoint(coord, &curDist);
             if (point.valid && curDist<minDist) {
@@ -1223,7 +1223,7 @@ RS_Vector RS_EntityContainer::getNearestEndpoint(const RS_Vector& coord,
     //    ++it;
 
     for(auto en: entities){
-        if (!en->getParent()->ignoredOnModification() ){//no end point for Insert, text, Dim
+        if (en->getParent() == nullptr || !en->getParent()->ignoredOnModification()) {//no end point for Insert, text, Dim
             //            std::cout<<"find nearest for entity "<<i0<<std::endl;
             point = en->getNearestEndpoint(coord, &curDist);
             if (point.valid && curDist<minDist) {
-- 
2.48.1

