Move sockets before disposing of them

This commit is contained in:
Alex Parisi committed 2026-05-14 14:31:31 -04:00
1 parent 96cb09da9e
commit 7c0b555629
1 file changed
+11 -10
+11 -10
View File
@@ -2114,16 +2114,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 == nullptr)
return true;
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
}