From 90db664635013f6e857ec696403f2164032410a8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 12 Apr 2022 12:49:19 +1000 Subject: Fix crash when deleting a buffer from a user mapping Deleting a buffer resets normal mode on all clients that were displaing that buffer, but ScopedForceNormalMode that are used from user mode do not take this possiblity into account on destruction, which leads to deleting the last normal mode from the context, ending up with an empty mode stack. Fixes #3909 --- src/input_handler.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/input_handler.cc') diff --git a/src/input_handler.cc b/src/input_handler.cc index 8adbbcee..26d255c0 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1698,14 +1698,9 @@ InputHandler::ScopedForceNormal::~ScopedForceNormal() if (m_mode == m_handler.m_mode_stack.back().get()) m_handler.pop_mode(m_mode); - else - { - auto it = find_if(m_handler.m_mode_stack, - [this](const RefPtr& m) - { return m.get() == m_mode; }); - kak_assert(it != m_handler.m_mode_stack.end()); + else if (auto it = find(m_handler.m_mode_stack, m_mode); + it != m_handler.m_mode_stack.end()) m_handler.m_mode_stack.erase(it); - } } static bool is_valid(Key key) -- cgit v1.2.3 From 5c6238ef113da8c2844ff9bcfa27c87e3473c150 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 1 May 2022 20:59:29 +1000 Subject: Remove invalid assert in ScopedForceNormal destructor commit 90db664635013f6e857ec696403f2164032410a8 introduced logic to handle the case where the mode had been removed, but did not get rid of the assert. --- src/input_handler.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/input_handler.cc') diff --git a/src/input_handler.cc b/src/input_handler.cc index 26d255c0..9b1857a8 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1694,8 +1694,6 @@ InputHandler::ScopedForceNormal::~ScopedForceNormal() if (not m_mode) return; - kak_assert(m_handler.m_mode_stack.size() > 1); - if (m_mode == m_handler.m_mode_stack.back().get()) m_handler.pop_mode(m_mode); else if (auto it = find(m_handler.m_mode_stack, m_mode); -- cgit v1.2.3