Skip to content

Commit

Permalink
Fixing an issue with the iterator of Dispatch Method which causing Se…
Browse files Browse the repository at this point in the history
…gFault when deactivating multiple OOP plugins (#263)
  • Loading branch information
volkan-aslan authored Nov 22, 2023
1 parent a5db2bd commit 9a6d1ad
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions MessageControl/MessageControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,41 +239,36 @@ namespace Plugin {

void Dispatch()
{
std::vector<uint32_t> attaching;
std::vector<uint32_t> detaching;

_adminLock.Lock();

bool done = false;

while (done == false) {
Observers::iterator index = _observing.begin();

while (done == false) {
if (index->second == state::ATTACHING) {
const uint32_t id = index->first;
index->second = state::OBSERVING;
_adminLock.Unlock();
_parent.Attach(id);
_adminLock.Lock();
break;
}
else if (index->second == state::DETACHING) {
const uint32_t id = index->first;
_observing.erase(index);
_adminLock.Unlock();
_parent.Detach(id);
_adminLock.Lock();
break;
}
else {
index++;

if (index == _observing.end()) {
done = true;
}
}
Observers::iterator index = _observing.begin();

while (index != _observing.end()) {
if (index->second == state::ATTACHING) {
attaching.emplace_back(index->first);
index->second = state::OBSERVING;
index++;
}
else if (index->second == state::DETACHING) {
detaching.emplace_back(index->first);
index = _observing.erase(index);
}
else {
index++;
}
}

_adminLock.Unlock();

for (const uint32_t& id : detaching) {
_parent.Detach(id);
}
for (const uint32_t& id : attaching) {
_parent.Attach(id);
}
}

private:
Expand Down

0 comments on commit 9a6d1ad

Please sign in to comment.