From e1549eb73c184c6609ccd768d35d51ce3d529278 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 31 Dec 2016 15:16:09 +0100 Subject: [PATCH] Fixed: Bug with C++11 under Linux with clang (an iterator is invalidated after an erase) --- code/ryzom/client/src/actions.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/code/ryzom/client/src/actions.cpp b/code/ryzom/client/src/actions.cpp index d2dffb504..6b9a3649b 100644 --- a/code/ryzom/client/src/actions.cpp +++ b/code/ryzom/client/src/actions.cpp @@ -148,9 +148,16 @@ void CActionsManager::removeCombo (const CCombo &combo) while ((ite != _KeyAction.end ()) && (ite->first == combo.Key)) { TKeyActionMap::iterator copyToDelete = ite; - ite++; +#ifdef NL_ISO_CPP0X_AVAILABLE + if (copyToDelete->second == oldName) + ite = _KeyAction.erase (copyToDelete); + else + ++ite; +#else + ++ite; if (copyToDelete->second == oldName) _KeyAction.erase (copyToDelete); +#endif } // Remove the action @@ -320,7 +327,7 @@ void CActionsManager::keyReleased (const CEventKeyUp &keyUp) TKeyActionMap::iterator iteWatchedAction = _WatchedActions.begin (); while (iteWatchedAction != _WatchedActions.end ()) { - TKeyActionMap::iterator iteToDelete = iteWatchedAction++; + TKeyActionMap::iterator iteToDelete = iteWatchedAction; // Get the combo for this action TActionComboMap::iterator iteCombo = _ActionCombo.find (iteToDelete->second); @@ -334,7 +341,15 @@ void CActionsManager::keyReleased (const CEventKeyUp &keyUp) nlassert (iteAction != _Actions.end()); // Remove this action from watching +#ifdef NL_ISO_CPP0X_AVAILABLE + // C++11 return the next item + iteWatchedAction = _WatchedActions.erase (iteToDelete); +#else + // remember the next iterator only if not using C++11 + ++iteWatchedAction; + _WatchedActions.erase (iteToDelete); +#endif // Invalidate the action bool LastValid = iteAction->second.Valide; @@ -349,6 +364,10 @@ void CActionsManager::keyReleased (const CEventKeyUp &keyUp) } } } + else + { + ++iteWatchedAction; + } } } }