forked from rosebudai/OpenRCT2-Web
Merge pull request #26558 from alex-parisi/null-socket-fix
Fixing crash when removing null socket
This commit is contained in:
1 file changed
+11
-8
@@ -2113,14 +2113,17 @@ void ScriptEngine::UpdateSockets()
|
||||
void ScriptEngine::RemoveSockets(const std::shared_ptr<Plugin>& plugin)
|
||||
{
|
||||
#ifndef DISABLE_NETWORK
|
||||
std::erase_if(_sockets, [plugin](const std::shared_ptr<SocketDataBase>& data) {
|
||||
if (data->_plugin == plugin)
|
||||
{
|
||||
data->Dispose();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// Remove sockets from the _plugins vector by first moving them, then clearing the vector
|
||||
std::vector<std::shared_ptr<SocketDataBase>> removed;
|
||||
for (auto& data : _sockets)
|
||||
{
|
||||
if (data != nullptr && data->_plugin == plugin)
|
||||
removed.push_back(std::move(data));
|
||||
}
|
||||
std::erase_if(_sockets, [](const std::shared_ptr<SocketDataBase>& data) { return data == nullptr; });
|
||||
// Dispose of the moved sockets safely
|
||||
for (const auto& data : removed)
|
||||
data->Dispose();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user