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
(cherry picked from commit 552815d486
)
This commit is contained in:
parent
a5cd5844ec
commit
9496b57b01
|
@ -2,6 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013-2018 CERN
|
* Copyright (C) 2013-2018 CERN
|
||||||
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||||
*
|
*
|
||||||
|
@ -374,11 +375,20 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool )
|
||||||
static_cast<TOOL_INTERACTIVE*>( aTool )->resetTransitions();
|
static_cast<TOOL_INTERACTIVE*>( aTool )->resetTransitions();
|
||||||
|
|
||||||
// If the tool is already active, bring it to the top of the active tools stack
|
// 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 ) );
|
auto it = std::find( m_activeTools.begin(), m_activeTools.end(), id );
|
||||||
m_activeTools.push_front( id );
|
|
||||||
return false;
|
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] );
|
setActiveState( m_toolIdIndex[id] );
|
||||||
|
|
Loading…
Reference in New Issue