From a4683e08f5e491026a714412ca185df9f230db72 Mon Sep 17 00:00:00 2001 From: Casey Langen Date: Thu, 15 Oct 2020 20:00:30 -0700 Subject: [PATCH] Fixed another potential MessageQueue issue. This should be the last one. --- src/musikcore/runtime/MessageQueue.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/musikcore/runtime/MessageQueue.cpp b/src/musikcore/runtime/MessageQueue.cpp index b7cda8287..07a076bf9 100755 --- a/src/musikcore/runtime/MessageQueue.cpp +++ b/src/musikcore/runtime/MessageQueue.cpp @@ -112,7 +112,12 @@ void MessageQueue::Dispatch() { EnqueuedMessage *m = (*it); if (now >= m->time) { - this->dispatch.push_back(m); + /* it's possible the target (receiver) has been unregistered; + if that's the case, just discard it. otherwise, add it to the + output set to be dispatched outside of the critical section */ + if (this->targets.find((*it)->message->Target()) != this->targets.end()) { + this->dispatch.push_back(m); + } it = this->queue.erase(it); } else { @@ -125,9 +130,7 @@ void MessageQueue::Dispatch() { Iterator it = this->dispatch.begin(); while (it != this->dispatch.end()) { - if (this->targets.find((*it)->message->Target()) != this->targets.end()) { - this->Dispatch((*it)->message); - } + this->Dispatch((*it)->message); delete *it; it++; }