diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 28c1cd323d..102454b362 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -1165,10 +1165,20 @@ void ScriptEngine::UpdateSockets() void ScriptEngine::RemoveSockets(const std::shared_ptr& plugin) { # ifndef DISABLE_NETWORK - _sockets.erase( - std::remove_if( - _sockets.begin(), _sockets.end(), [&plugin](const auto& socket) { return socket->GetPlugin() == plugin; }), - _sockets.end()); + auto it = _sockets.begin(); + while (it != _sockets.end()) + { + auto socket = it->get(); + if (socket->GetPlugin() == plugin) + { + socket->Dispose(); + it = _sockets.erase(it); + } + else + { + it++; + } + } # endif }