From ba3c6ec3da54d0d55ea1f7a4df7246b40a078e5f Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Fri, 3 Nov 2017 07:48:49 +1100 Subject: [PATCH] Fixed floating label context dtors sometimes getting stuck in an infinite loop This fixes #2154. For some reason, after opening help from the File menu and then quitting to desktop, the number of labels recorded in the label map and context set weren't equal. I'm not exactly sure why, since the code seems to indicate they should be, and the loop doesn't seem to be hit when only invoking help with the hotkey (F1). This just removes the predication of a label being present in the label map for removal from the context set. I also removed two useless, unused variables that I'm surprised no one's complained about. --- src/floating_label.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/floating_label.cpp b/src/floating_label.cpp index efbff5c7626..ebbc06a8713 100644 --- a/src/floating_label.cpp +++ b/src/floating_label.cpp @@ -227,12 +227,12 @@ void remove_floating_label(int handle) { const label_map::iterator i = labels.find(handle); if(i != labels.end()) { - if(label_contexts.empty() == false) { - label_contexts.top().erase(i->first); - } - labels.erase(i); } + + if(!label_contexts.empty()) { + label_contexts.top().erase(handle); + } } void show_floating_label(int handle, bool value) @@ -257,24 +257,20 @@ SDL_Rect get_floating_label_rect(int handle) floating_label_context::floating_label_context() { - const surface screen = nullptr; - label_contexts.emplace(); } floating_label_context::~floating_label_context() { const std::set& context = label_contexts.top(); - while (!context.empty()) - { + + while(!context.empty()) { // Remove_floating_label removes the passed label from the context. // This loop removes a different label in every iteration. remove_floating_label(*context.begin()); } label_contexts.pop(); - - const surface screen = nullptr; } void draw_floating_labels(surface screen)