Skip to content

Commit

Permalink
Fix debugger plugin not cleaning up all event listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Apr 10, 2023
1 parent 5267e77 commit 8504531
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
37 changes: 20 additions & 17 deletions Source/Debugger/DebuggerPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,7 @@ bool DebuggerPlugin::SetContext(Context* context)
// Attach the info element to the new context.
if (info_element)
{
if (debug_context)
{
debug_context->RemoveEventListener("click", info_element, true);
debug_context->RemoveEventListener("mouseover", info_element, true);
debug_context->RemoveEventListener("mouseout", info_element, true);
}

if (context)
{
context->AddEventListener("click", info_element, true);
context->AddEventListener("mouseover", info_element, true);
context->AddEventListener("mouseout", info_element, true);
}

SetupInfoListeners(context);
info_element->Reset();
}

Expand Down Expand Up @@ -373,15 +360,31 @@ bool DebuggerPlugin::LoadLogElement()
return true;
}

void DebuggerPlugin::ReleaseElements()
void DebuggerPlugin::SetupInfoListeners(Rml::Context* new_context)
{
// Erase event listeners to prevent crashes.
if (debug_context && info_element)
RMLUI_ASSERT(info_element);

if (debug_context)
{
debug_context->RemoveEventListener("click", info_element, true);
debug_context->RemoveEventListener("mouseover", info_element, true);
debug_context->RemoveEventListener("mouseout", info_element, true);
}

if (new_context)
{
new_context->AddEventListener("click", info_element, true);
new_context->AddEventListener("mouseover", info_element, true);
new_context->AddEventListener("mouseout", info_element, true);
}
}

void DebuggerPlugin::ReleaseElements()
{
// Erase event listeners to prevent crashes.
if (info_element)
SetupInfoListeners(nullptr);

if (host_context)
{
if (menu_element)
Expand Down
2 changes: 2 additions & 0 deletions Source/Debugger/DebuggerPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class DebuggerPlugin : public Rml::Plugin, public Rml::EventListener
bool LoadInfoElement();
bool LoadLogElement();

void SetupInfoListeners(Rml::Context* new_context);

// Release all loaded elements
void ReleaseElements();

Expand Down

0 comments on commit 8504531

Please sign in to comment.