Skip to content

Instantly share code, notes, and snippets.

@Costava
Created August 11, 2022 04:36
Show Gist options
  • Save Costava/eff04acf3816dddf7ee64ace04d38e1a to your computer and use it in GitHub Desktop.
Save Costava/eff04acf3816dddf7ee64ace04d38e1a to your computer and use it in GitHub Desktop.

SteamNetworkingSockets() is returning nullptr

Problem: The SteamNetworkingSockets() call from the GameNetworkingSockets library is returning nullptr.

Fix: You are probably missing some initialization prior to that. Look at the function InitSteamDatagramConnectionSockets from the repo's example_chat.cpp:

static void InitSteamDatagramConnectionSockets()
{
	#ifdef STEAMNETWORKINGSOCKETS_OPENSOURCE
		SteamDatagramErrMsg errMsg;
		if ( !GameNetworkingSockets_Init( nullptr, errMsg ) )
			FatalError( "GameNetworkingSockets_Init failed.  %s", errMsg );
	#else
		SteamDatagram_SetAppID( 570 ); // Just set something, doesn't matter what
		SteamDatagram_SetUniverse( false, k_EUniverseDev );

		SteamDatagramErrMsg errMsg;
		if ( !SteamDatagramClient_Init( errMsg ) )
			FatalError( "SteamDatagramClient_Init failed.  %s", errMsg );

		// Disable authentication when running with Steam, for this
		// example, since we're not a real app.
		//
		// Authentication is disabled automatically in the open-source
		// version since we don't have a trusted third party to issue
		// certs.
		SteamNetworkingUtils()->SetGlobalConfigValueInt32( k_ESteamNetworkingConfig_IP_AllowWithoutAuth, 1 );
	#endif

	g_logTimeZero = SteamNetworkingUtils()->GetLocalTimestamp();

	SteamNetworkingUtils()->SetDebugOutputFunction( k_ESteamNetworkingSocketsDebugOutputType_Msg, DebugOutput );
}

via https://github.com/ValveSoftware/GameNetworkingSockets/blob/v1.4.1/examples/example_chat.cpp#L93-L119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment