diff --git a/src/inputsystem/inputstacksystem.cpp b/src/inputsystem/inputstacksystem.cpp index cbab340f..723a22a1 100644 --- a/src/inputsystem/inputstacksystem.cpp +++ b/src/inputsystem/inputstacksystem.cpp @@ -31,16 +31,30 @@ InputContextHandle_t CInputStackSystem::PushInputContext() //----------------------------------------------------------------------------- -// Pops the top input context off the input stack, and destroys it. +// Pops the provided input context off the input stack, and destroys it. //----------------------------------------------------------------------------- -void CInputStackSystem::PopInputContext( InputContextHandle_t hContext ) +void CInputStackSystem::PopInputContext( InputContextHandle_t& hContext ) { - if ( m_ContextStack.Count() == 0 ) + const int nCount = m_ContextStack.Count(); + + if ( nCount == 0 ) return; - InputContext_t *pContext = NULL; - m_ContextStack.Pop( pContext ); - delete pContext; + int i = 0; + InputContext_t *pContext = *m_ContextStack.Base(); + + // Find the context. + for ( ; pContext != (InputContext_t*)hContext; pContext++ ) + { + if ( ++i == nCount ) + { + Assert( 0 ); + return; + } + } + + m_ContextStack.PopAt( i ); + hContext = INPUT_CONTEXT_HANDLE_INVALID; UpdateCursorState(); } diff --git a/src/inputsystem/inputstacksystem.h b/src/inputsystem/inputstacksystem.h index 8593a703..1c4d8455 100644 --- a/src/inputsystem/inputstacksystem.h +++ b/src/inputsystem/inputstacksystem.h @@ -41,7 +41,7 @@ public: // Methods of IInputStackSystem public: virtual InputContextHandle_t PushInputContext(); - virtual void PopInputContext( InputContextHandle_t hContext ); + virtual void PopInputContext( InputContextHandle_t& hContext ); virtual void EnableInputContext( InputContextHandle_t hContext, bool bEnable ); virtual void SetCursorVisible( InputContextHandle_t hContext, bool bVisible ); virtual void SetCursorIcon( InputContextHandle_t hContext, InputCursorHandle_t hCursor );