tool_mgr: Don't invalidate our own iterators

Re-arranging the stack will invalidate the iterator that is removed and
inserted (begin()).  Because this is not a threaded operation, we can
only do it to ourselves, so check that the operation isn't a NOP before
performing.

Fixes: lp:1832930
* https://bugs.launchpad.net/kicad/+bug/1832930
This commit is contained in:
Seth Hillbrand 2019-06-15 17:47:18 -07:00
parent 0f4bdbd184
commit 552815d486
1 changed files with 14 additions and 4 deletions

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013-2018 CERN
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
@ -362,11 +363,20 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool )
static_cast<TOOL_INTERACTIVE*>( aTool )->resetTransitions();
// If the tool is already active, bring it to the top of the active tools stack
if( isActive( aTool ) )
if( isActive( aTool ) && m_activeTools.size() > 1 )
{
m_activeTools.erase( std::find( m_activeTools.begin(), m_activeTools.end(), id ) );
m_activeTools.push_front( id );
return false;
auto it = std::find( m_activeTools.begin(), m_activeTools.end(), id );
if( it != m_activeTools.end() )
{
if( it != m_activeTools.begin() )
{
m_activeTools.erase( it );
m_activeTools.push_front( id );
}
return false;
}
}
setActiveState( m_toolIdIndex[id] );