Skip to content
Permalink
Browse files

UI: Clear queued events on Event destruct.

May help a crash seen in #11890.
  • Loading branch information...
unknownbrackets committed Jun 23, 2019
1 parent 3a98a5d commit 8c282db2259397f588adf119fc0f776e0d777a38
Showing with 22 additions and 6 deletions.
  1. +21 −3 ext/native/ui/view.cpp
  2. +1 −3 ext/native/ui/view.h
@@ -60,9 +60,22 @@ void DispatchEvents() {
}

void RemoveQueuedEvents(View *v) {
for (size_t i = 0; i < g_dispatchQueue.size(); i++) {
if (g_dispatchQueue[i].params.v == v)
g_dispatchQueue.erase(g_dispatchQueue.begin() + i);
for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) {
if (it->params.v == v) {
it = g_dispatchQueue.erase(it);
} else {
++it;
}
}
}

void RemoveQueuedEvents(Event *e) {
for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) {
if (it->e == e) {
it = g_dispatchQueue.erase(it);
} else {
++it;
}
}
}

@@ -157,6 +170,11 @@ EventReturn Event::Dispatch(EventParams &e) {
return UI::EVENT_SKIPPED;
}

Event::~Event() {
handlers_.clear();
RemoveQueuedEvents(this);
}

View::~View() {
if (HasFocus())
SetFocusedView(0);
@@ -240,9 +240,7 @@ struct HandlerRegistration {
class Event {
public:
Event() {}
~Event() {
handlers_.clear();
}
~Event();
// Call this from input thread or whatever, it doesn't matter
void Trigger(EventParams &e);
// Call this from UI thread

0 comments on commit 8c282db

Please sign in to comment.
You can’t perform that action at this time.