Merge pull request #26558 from alex-parisi/null-socket-fix

Fixing crash when removing null socket
This commit is contained in:
Tulio Leao authored and GitHub committed 2026-05-16 22:28:49 -03:00
commit d093945c41
1 file changed
+11 -8
+11 -8
View File
@@ -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
}