From 6d609d183795a9e682da7387586d73872e899697 Mon Sep 17 00:00:00 2001 From: lifekidyeaa Date: Fri, 14 Mar 2008 05:47:35 +0000 Subject: [PATCH] Fixed segfault which occured when open ing the module editor, loading a module, closing it, and opening the module editor again. This was caused by prematurely deleting the module editor's m_Pcb pointer, which has the same value (points to the same structure) as g_ModuleEditor_Pcb hence should not be deleted. --- include/wxstruct.h | 2 +- pcbnew/basepcbframe.cpp | 3 ++- pcbnew/locate.cpp | 2 +- pcbnew/moduleframe.cpp | 2 +- pcbnew/pcbframe.cpp | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/wxstruct.h b/include/wxstruct.h index 3299780851..1aa72a5ffb 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -21,7 +21,7 @@ #include #ifndef SAFE_DELETE -#define SAFE_DELETE(p) delete (p); (p) = NULL; +#define SAFE_DELETE(p) delete (p); (p) = NULL; //C++ guarantees that operator delete checks its argument for null-ness #endif #define INTERNAL_UNIT_TYPE 0 // Internal unit = inch diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 8c927cb11e..990217b04a 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -68,7 +68,8 @@ WinEDA_BasePcbFrame::~WinEDA_BasePcbFrame( void ) void WinEDA_BasePcbFrame::SetBOARD( BOARD* aBoard ) { - delete m_Pcb; + if(m_Pcb != g_ModuleEditor_Pcb) + delete m_Pcb; m_Pcb = aBoard; } diff --git a/pcbnew/locate.cpp b/pcbnew/locate.cpp index a23e459fd1..1a2bccfa35 100644 --- a/pcbnew/locate.cpp +++ b/pcbnew/locate.cpp @@ -382,7 +382,7 @@ TRACK* Locate_Piste_Connectee( TRACK* PtRefSegm, TRACK* pt_base, if( PtSegmN == PtRefSegm ) goto suite; - /* max_dist is the max distance between 2 tack ends which ensure a copper continuty */ + /* max_dist is the max distance between 2 track ends which ensure a copper continuty */ max_dist = (PtSegmN->m_Width + PtRefSegm->m_Width)/2; if( IsPointsAreNear(pos_ref, PtSegmN->m_Start, max_dist) ) diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 3cad0e876e..3c41a5ef2a 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -136,7 +136,7 @@ WinEDA_ModuleEditFrame::WinEDA_ModuleEditFrame( wxWindow* father, WinEDA_App* pa m_Pcb->m_PcbFrame = this; m_CurrentScreen = ScreenModule; - SetCurItem( NULL ); + m_CurrentScreen->SetCurItem( NULL ); GetSettings(); wxSize GridSize( 500, 500 ); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index eb5d48b81e..4889600e70 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -250,7 +250,7 @@ WinEDA_PcbFrame::~WinEDA_PcbFrame() m_Parent->m_PcbFrame = NULL; m_CurrentScreen = ScreenPcb; delete m_drc; - delete m_Pcb; + if(m_Pcb != g_ModuleEditor_Pcb) delete m_Pcb; }