Prevent invalid decrement in tool manager

Iterating over the tool stack, we potentially remove the current
iterator.  If this removal happens at the beginning of the toolstack, we
cannot decrement the iterator to a position before the stack without
creating an invalid state.
This commit is contained in:
Seth Hillbrand 2020-04-20 11:49:25 -07:00
parent 94e2690fed
commit 1770a1ea21
1 changed files with 11 additions and 2 deletions

View File

@ -648,17 +648,23 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchInternal %s", aEvent.Format() );
auto it = m_activeTools.begin();
// iterate over active tool stack
for( auto it = m_activeTools.begin(); it != m_activeTools.end(); ++it )
while( it != m_activeTools.end() )
{
TOOL_STATE* st = m_toolIdIndex[*it];
bool increment = true;
// forward context menu events to the tool that created the menu
if( aEvent.IsChoiceMenu() )
{
if( *it != m_menuOwner )
{
++it;
continue;
}
}
// the tool state handler is waiting for events (i.e. called Wait() method)
if( st && st->pendingWait )
@ -685,7 +691,7 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
if( end )
{
it = finishTool( st );
--it;
increment = false;
}
}
@ -701,6 +707,9 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
}
}
}
if( increment )
++it;
}
for( auto& state : m_toolState )