From d299c55ea4aa98a91a619326e095a42f91f34395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liru=20F=C3=A6rs?= Date: Wed, 1 Jan 2020 02:59:23 -0500 Subject: [PATCH] Ve must erase ze kinderlach!! Fixes Error 3, which was caused by deref of invalidated iterator --- indra/llui/lllineeditor.cpp | 3 +-- indra/llui/llmenugl.h | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index af5664ed6..189317342 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -3015,8 +3015,7 @@ void LLLineEditor::showContextMenu(S32 x, S32 y) { constexpr auto spell_sep = "Spell Check Sep"; // Remove everything after the separator if we added it, because menus don't autodie yet. - for (auto menu_end = menu->end(), menu_it = menu->find(menu->findChild(spell_sep)); menu_it != menu_end; ++menu_it) - menu->removeChild(*menu_it); + menu->erase(menu->find(menu->findChild(spell_sep)), menu->end()); menu->addSeparator(spell_sep); // search for word matches diff --git a/indra/llui/llmenugl.h b/indra/llui/llmenugl.h index c3d0616a6..5283465a2 100644 --- a/indra/llui/llmenugl.h +++ b/indra/llui/llmenugl.h @@ -527,10 +527,16 @@ public: // erase group of items from menu void erase(S32 begin, S32 end, bool arrange = true); + typedef std::list item_list_t; + inline item_list_t::iterator erase(item_list_t::const_iterator first, item_list_t::const_iterator last) + { + for (auto it = first; it != last; ++it) + LLUICtrl::removeChild(*it); + return mItems.erase(first, last); + } // add new item at position void insert(S32 begin, LLView* ctrl, bool arrange = true); - typedef std::list item_list_t; void insert(item_list_t::const_iterator position_iter, LLMenuItemGL* item, bool arrange = true); // find an item's position