diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index ca02f2f70a..a2a7d6c8aa 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -63,6 +63,16 @@ public: return wxT( "DELETED_SHEET_ITEM" ); } + static DELETED_SHEET_ITEM* GetInstance() + { + static DELETED_SHEET_ITEM* item = nullptr; + + if( !item ) + item = new DELETED_SHEET_ITEM(); + + return item; + } + // pure virtuals: void SetPosition( const wxPoint& ) override {} void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override {} @@ -76,8 +86,6 @@ public: #endif }; -DELETED_SHEET_ITEM* g_DeletedItem = nullptr; - namespace std { @@ -530,10 +538,7 @@ SCH_ITEM* SCH_SHEET_LIST::GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut ) } // Not found; weak reference has been deleted. - if( !g_DeletedItem ) - g_DeletedItem = new DELETED_SHEET_ITEM(); - - return g_DeletedItem; + return DELETED_SHEET_ITEM::GetInstance(); } diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 1f1b806644..5342a9efcb 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -76,6 +76,15 @@ public: return wxPoint(0, 0); } + static DELETED_BOARD_ITEM* GetInstance() + { + static DELETED_BOARD_ITEM* item = nullptr; + + if( !item ) + item = new DELETED_BOARD_ITEM(); + + return item; + } #if defined(DEBUG) void Show( int , std::ostream& ) const override {} @@ -807,10 +816,7 @@ BOARD_ITEM* BOARD::GetItem( const KIID& aID ) return this; // Not found; weak reference has been deleted. - if( !g_DeletedItem ) - g_DeletedItem = new DELETED_BOARD_ITEM(); - - return g_DeletedItem; + return DELETED_BOARD_ITEM::GetInstance(); }