From 9d98fe1b80f36645bafc7fc4dcdbd814a537dde1 Mon Sep 17 00:00:00 2001 From: Miles McCoo Date: Tue, 6 Mar 2018 09:28:57 +0100 Subject: [PATCH] Fix for crash due to pcbnew_action_plugin object tracking pcbnew_action_plug tracks items that were modified within a plugin. In the case of deletion, the old object is no longer valid. This commit turns off the call to delete if a plugin is active. --- pcbnew/action_plugin.cpp | 15 +++++++++++++++ pcbnew/action_plugin.h | 14 +++++++++++++- pcbnew/swig/board_item_container.i | 3 ++- pcbnew/swig/pcbnew_action_plugins.cpp | 2 ++ pcbnew/swig/pcbnew_scripting_helpers.cpp | 7 +++++++ pcbnew/swig/pcbnew_scripting_helpers.h | 5 +++++ 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/pcbnew/action_plugin.cpp b/pcbnew/action_plugin.cpp index 799674510e..c10d0fafe2 100644 --- a/pcbnew/action_plugin.cpp +++ b/pcbnew/action_plugin.cpp @@ -44,6 +44,9 @@ void ACTION_PLUGIN::register_action() std::vector ACTION_PLUGINS::m_actionsList; +bool ACTION_PLUGINS::m_actionRunning = false; + + ACTION_PLUGIN* ACTION_PLUGINS::GetAction( int aIndex ) { return m_actionsList[aIndex]; @@ -147,3 +150,15 @@ bool ACTION_PLUGINS::deregister_object( void* aObject ) return false; } + + +bool ACTION_PLUGINS::IsActionRunning() +{ + return ACTION_PLUGINS::m_actionRunning; +} + + +void ACTION_PLUGINS::SetActionRunning( bool aRunning ) +{ + ACTION_PLUGINS::m_actionRunning = aRunning; +} diff --git a/pcbnew/action_plugin.h b/pcbnew/action_plugin.h index 9552e1ac0b..ff3ed14559 100644 --- a/pcbnew/action_plugin.h +++ b/pcbnew/action_plugin.h @@ -101,7 +101,7 @@ private: * ACTION_PLUGIN system wide static list */ static std::vector m_actionsList; - + static bool m_actionRunning; public: /** * Function register_action @@ -168,6 +168,18 @@ public: * @return the number of actions available into the system */ static int GetActionsCount(); + + /** + * Function IsActionRunning + * @return Is an action running right now + */ + static bool IsActionRunning(); + + /** + * Function SetActionRunning + * @param aRunning sets whether an action is running now. + */ + static void SetActionRunning( bool aRunning ); }; #endif /* PCBNEW_ACTION_PLUGINS_H */ diff --git a/pcbnew/swig/board_item_container.i b/pcbnew/swig/board_item_container.i index aadc06915c..337adfab86 100644 --- a/pcbnew/swig/board_item_container.i +++ b/pcbnew/swig/board_item_container.i @@ -32,7 +32,8 @@ Remove(self, BOARD_ITEM) """ self.RemoveNative(item) - item.thisown=1 + if (not IsActionRunning()): + item.thisown=1 def Delete(self,item): """ diff --git a/pcbnew/swig/pcbnew_action_plugins.cpp b/pcbnew/swig/pcbnew_action_plugins.cpp index ef18cde09e..2d68e4af33 100644 --- a/pcbnew/swig/pcbnew_action_plugins.cpp +++ b/pcbnew/swig/pcbnew_action_plugins.cpp @@ -230,7 +230,9 @@ void PCB_EDIT_FRAME::OnActionPlugin( wxCommandEvent& aEvent ) itemsList.ClearItemsList(); // Execute plugin himself... + ACTION_PLUGINS::SetActionRunning( true ); actionPlugin->Run(); + ACTION_PLUGINS::SetActionRunning( false ); currentPcb->m_Status_Pcb = 0; diff --git a/pcbnew/swig/pcbnew_scripting_helpers.cpp b/pcbnew/swig/pcbnew_scripting_helpers.cpp index 3dbedc32c9..065c029f75 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.cpp +++ b/pcbnew/swig/pcbnew_scripting_helpers.cpp @@ -40,6 +40,7 @@ #include #include #include +#include static PCB_EDIT_FRAME* s_PcbEditFrame = NULL; @@ -135,3 +136,9 @@ void UpdateUserInterface() if( s_PcbEditFrame ) s_PcbEditFrame->UpdateUserInterface(); } + + +bool IsActionRunning() +{ + return ACTION_PLUGINS::IsActionRunning(); +} diff --git a/pcbnew/swig/pcbnew_scripting_helpers.h b/pcbnew/swig/pcbnew_scripting_helpers.h index e0a0ae9a0f..6233b3ac5b 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.h +++ b/pcbnew/swig/pcbnew_scripting_helpers.h @@ -69,4 +69,9 @@ void WindowZoom( int xl, int yl, int width, int height ); */ void UpdateUserInterface(); +/** + * Are we currently in an action plugin? + */ +bool IsActionRunning(); + #endif // __PCBNEW_SCRIPTING_HELPERS_H