Remove deleted item global variables

Fixes https://gitlab.com/kicad/code/kicad/issues/4819
This commit is contained in:
Ian McInerney 2020-07-07 00:55:38 +01:00
parent 7cea4b23f1
commit ccc0ceb32f
2 changed files with 21 additions and 10 deletions

View File

@ -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();
}

View File

@ -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();
}