Skip to content

Commit e5b50aa

Browse files
authored
Merge pull request #492 from GeneralsOnlineDevelopmentTeam/seer/fix/network-reinit-race
bugfix(network): Prevent crash during Steam Networking Sockets re-initialization
2 parents 4d17055 + 52aa639 commit e5b50aa

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline

GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NetworkMesh.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,15 @@ NetworkMesh::NetworkMesh()
566566
{
567567
SteamNetworkingUtils()->SetGlobalConfigValueInt32(k_ESteamNetworkingConfig_LogLevel_P2PRendezvous, k_ESteamNetworkingSocketsDebugOutputType_Error);
568568

569+
// Block the status-changed callback from firing while the library is
570+
// torn down and re-initialized. Without this guard the callback can
571+
// be dispatched (e.g. from a previous Tick's RunCallbacks queue) after
572+
// GameNetworkingSockets_Kill() has freed its internal mutexes but
573+
// before GameNetworkingSockets_Init() has rebuilt them, resulting in
574+
// an EXCEPTION_ACCESS_VIOLATION_READ on a null mutex pointer inside
575+
// mtx_do_lock.
576+
g_bNetworkMeshDestroying.store(true);
577+
569578
// try a shutdown
570579
GameNetworkingSockets_Kill();
571580

@@ -658,6 +667,10 @@ NetworkMesh::NetworkMesh()
658667

659668
SteamNetworkingUtils()->SetGlobalCallback_SteamNetConnectionStatusChanged(OnSteamNetConnectionStatusChanged);
660669

670+
// Library is fully re-initialized and the callback is registered;
671+
// it is now safe to allow OnSteamNetConnectionStatusChanged to run.
672+
g_bNetworkMeshDestroying.store(false);
673+
661674
ESteamNetworkingSocketsDebugOutputType logType =
662675
#if defined(_DEBUG)
663676
ESteamNetworkingSocketsDebugOutputType::k_ESteamNetworkingSocketsDebugOutputType_Debug

0 commit comments

Comments
 (0)