Fixes #2579 Emesary segfault on reset.

Need to call OnDeregister before the object is deleted (because not using smart pointers for receivers).
This commit is contained in:
Richard Harrison 2021-05-02 17:34:33 +02:00
parent 5e30d83a43
commit 8464ef48e8
2 changed files with 6 additions and 3 deletions

View File

@ -38,7 +38,8 @@ namespace simgear
{
}
/// Called when de-registered at a transmitter
/// Called when de-registered at a transmitter; i.e. as a result of
/// Transmitter::DeRegister.
virtual void OnDeRegisteredAtTransmitter(class Transmitter *p)
{
}

View File

@ -89,7 +89,9 @@ namespace simgear
}
}
// Removes an object from receving message from this transmitter
/// Removes an object from receving message from this transmitter.
/// NOTES: OnDeRegisteredAtTransmitter will be called as a result of this method
/// If recipient is in the list of new recipients it will be removed from that list
virtual void DeRegister(IReceiverPtr r)
{
std::lock_guard<std::mutex> scopeLock(_lock);
@ -102,6 +104,7 @@ namespace simgear
new_recipient_list.erase(location);
}
deleted_recipient_list.push_back(r);
r->OnDeRegisteredAtTransmitter(this);
pendingDeletions++;
}
@ -125,7 +128,6 @@ namespace simgear
RecipientList::iterator location = std::find(recipient_list.begin(), recipient_list.end(), r);
if (location != recipient_list.end()) {
r->OnDeRegisteredAtTransmitter(this);
recipient_list.erase(location);
}
});