From 641c8bb5488ec60c1da8e2d495d2eff77bec3406 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 26 Apr 2018 19:42:39 +0200 Subject: [PATCH] PCBNew: Fix crash while routing in Legacy canvas it was due to a incorrect behavior of TRACK::GetBestInsertPoint( BOARD* aPcb ) Also: update comment for this method. Fixes: lp:1767061 https://bugs.launchpad.net/kicad/+bug/1767061 --- pcbnew/class_track.cpp | 5 ++++- pcbnew/class_track.h | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index ffee2c26be..e4c7a9866d 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -512,7 +512,10 @@ TRACK* TRACK::GetBestInsertPoint( BOARD* aPcb ) return track->Next(); } - return NULL; + if( Type() == PCB_ZONE_T ) + return aPcb->m_Zone.GetFirst(); + else + return aPcb->m_Track.GetFirst(); } diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index 1da81e6ff7..a227cd8341 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -147,10 +147,13 @@ public: /** * Function GetBestInsertPoint * searches the "best" insertion point within the track linked list. - * The best point is the begging of the corresponding net code section. + * The best point is currently the end of the corresponding net code section. * (The BOARD::m_Track and BOARD::m_Zone lists are sorted by netcode.) * @param aPcb The BOARD to search for the insertion point. - * @return TRACK* - the item found in the linked list (or NULL if no track) + * @return TRACK* - the insertion point in the linked list. + * this is the next item after the last item having my net code. + * therefore the track to insert must be inserted before the insertion point. + * if the best insertion point is the end of list, the returned value is NULL */ TRACK* GetBestInsertPoint( BOARD* aPcb );