Fixed another potential MessageQueue issue. This should be the last one.

This commit is contained in:
Casey Langen 2020-10-15 20:00:30 -07:00
parent d628fabf71
commit a4683e08f5

View File

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