diff --git a/kicad/kicad.h b/kicad/kicad.h index 4a19375412..9606337fe6 100644 --- a/kicad/kicad.h +++ b/kicad/kicad.h @@ -36,6 +36,7 @@ #include #include #include +#include #define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" ) @@ -304,6 +305,9 @@ private: void language_change( wxCommandEvent& event ); bool m_active_project; + + // Mutex to allow only a single KiFace to load at one time (released when loaded) + std::mutex m_loading; }; diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp index c75661485d..63efacce0a 100644 --- a/kicad/mainframe.cpp +++ b/kicad/mainframe.cpp @@ -316,6 +316,9 @@ void KICAD_MANAGER_FRAME::RunEeschema( const wxString& aProjectSchematicFileName { KIWAY_PLAYER* frame; + // Prevent multiple KiFace loading at one time + const std::lock_guard lock( m_loading ); + try { frame = Kiway().Player( FRAME_SCH, true ); @@ -361,6 +364,9 @@ void KICAD_MANAGER_FRAME::OnRunSchLibEditor( wxCommandEvent& event ) { KIWAY_PLAYER* frame; + // Prevent multiple KiFace loading at one time + const std::lock_guard lock( m_loading ); + try { frame = Kiway().Player( FRAME_SCH_LIB_EDITOR, true ); @@ -387,6 +393,9 @@ void KICAD_MANAGER_FRAME::RunPcbNew( const wxString& aProjectBoardFileName ) { KIWAY_PLAYER* frame; + // Prevent multiple KiFace loading at one time + const std::lock_guard lock( m_loading ); + try { frame = Kiway().Player( FRAME_PCB, true ); @@ -430,6 +439,9 @@ void KICAD_MANAGER_FRAME::OnRunPcbFpEditor( wxCommandEvent& event ) { KIWAY_PLAYER* frame; + // Prevent multiple KiFace loading at one time + const std::lock_guard lock( m_loading ); + try { frame = Kiway().Player( FRAME_PCB_MODULE_EDITOR, true );