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++; }