Skip to content

Instantly share code, notes, and snippets.

@bearlikelion
Last active August 23, 2025 17:27
Show Gist options
  • Save bearlikelion/bf874e8a7001228500b0574760cfd0d6 to your computer and use it in GitHub Desktop.
Save bearlikelion/bf874e8a7001228500b0574760cfd0d6 to your computer and use it in GitHub Desktop.
Godot SMP Linux Crashfix
diff --git a/godotsteam_multiplayer_peer.cpp b/godotsteam_multiplayer_peer.cpp
index df4b525..b190601 100644
--- a/godotsteam_multiplayer_peer.cpp
+++ b/godotsteam_multiplayer_peer.cpp
@@ -270,6 +270,8 @@ void SteamMultiplayerPeer::lobby_chat_update(LobbyChatUpdate_t *p_chat_update) {
add_peer(p_chat_update->m_ulSteamIDUserChanged);
} else {
// If they didn't enter, it doesn't matter why, they are leaving
+ // Collect connections to remove to avoid iterator invalidation
+ LocalVector<HSteamNetConnection> connections_to_remove;
for (KeyValue<HSteamNetConnection, Ref<SteamPacketPeer>> &E :
steam_connections) {
if (E.value->get_steam_id() == p_chat_update->m_ulSteamIDUserChanged) {
@@ -278,10 +280,14 @@ void SteamMultiplayerPeer::lobby_chat_update(LobbyChatUpdate_t *p_chat_update) {
} else {
// We have an open connection but no peer
E.value->disconnect_peer(true);
- steam_connections.erase(E.value->get_connection_handle());
+ connections_to_remove.push_back(E.value->get_connection_handle());
}
}
}
+ // Remove collected connections outside the iteration
+ for (HSteamNetConnection conn : connections_to_remove) {
+ steam_connections.erase(conn);
+ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment