Skip to content

Commit

Permalink
Fixed floating label context dtors sometimes getting stuck in an infi…
Browse files Browse the repository at this point in the history
…nite 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.
  • Loading branch information
Vultraz committed Nov 2, 2017
1 parent a82eb44 commit ba3c6ec
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/floating_label.cpp
Expand Up @@ -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)
Expand All @@ -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<int>& 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)
Expand Down

0 comments on commit ba3c6ec

Please sign in to comment.