On Windows 64bits, I am facing a crash using the Steamworks sdk in C++.
#include <iostream>
#include <steam_api.h>
#include <isteamapps.h>
#include <isteamfriends.h>
#include <isteamuser.h>
int main(int argc, char const *argv[])
{
SteamErrMsg errMsg;
if (SteamAPI_InitEx(&errMsg) == k_ESteamAPIInitResult_OK) {
auto steamUser = SteamUser();
if (steamUser) {
std::cout << "SteamUser() is valid." << std::endl;
try {
CSteamID steamID = steamUser->GetSteamID();
std::cout << "SteamID: " << steamID.ConvertToUint64() << std::endl;
} catch (const std::exception &e) {
std::cout << "Exception occurred" << std::endl;
}
} else {
std::cout << "SteamUser() is nullptr." << std::endl;
}
SteamAPI_Shutdown();
} else {
std::cout << "Failed to initialize Steam API." << std::endl;
}
return 0;
}
With gdb, we can see the crash occurs in a steam function of steamclient.dll, on that line:
CSteamID steamID = steamUser->GetSteamID();
warning: [S_API] SteamAPI_Init(): Loaded 'C:\Program Files (x86)\Steam\steamclient64.dll' OK.
Setting breakpad minidump AppID = 3025660
SteamInternal_SetMinidumpSteamID: Caching Steam ID: 76561198137762511 [API loaded no]
Initialize Steam API OK.
SteamUser() is valid.
Thread 1 "MainThrd" received signal SIGSEGV, Segmentation fault.
0x00007ffead18e225 in steamclient64!Steam_NotifyMissingInterface ()
from C:\Program Files (x86)\Steam\steamclient64.dll
I tried with different version of steam sdk.
I tried reinstall Steam client.
On Linux the code provided works perfectly.
I have also tried to have more info withing the steam consol steam api debug describe here.
This is the most verbose output I have during the execution of my example program. I didnt find anything suspicious.
] log_ipc game_obj.exe
Started IPC logging for game_obj.exe.
Each IPC call is being logged to C:\Program Files (x86)\Steam\logs\ipc_SteamClient.log.
You can stop logging IPC calls using "log_ipc 0"
00003005 game_obj.exe:458755 > IClientUtils::GetSteamRealm( ) = 1,
00003006 game_obj.exe:458755 > IClientUtils::GetConnectedUniverse( ) = 1,
00003006 game_obj.exe:458755 > IClientUtils::GetIPCountry( ) = "FR",
00003006 game_obj.exe:458755 > IClientUtils::GetServerRealTime( ) = 1719931821,
[2024-07-02 16:50:22] AppID 3025660 adding PID 9280 as a tracked process ""C:\Users\maman\test_steam_api\install\game_obj.exe""
Game process added : AppID 3025660 ""C:\Users\maman\test_steam_api\install\game_obj.exe"", ProcID 9280, IP 0.0.0.0:0
[2024-07-02 16:50:22] SSGL: InternalUpdateClientGame indicates change to games list
CClientMusic::OnAppEventStateChange 3025660 4 2004
00003007 game_obj.exe:458755 > IClientUtils::SetAppIDForCurrentPipe( 3025660, 1, ) = 3025660,
00003015 game_obj.exe:458755 > IClientApps::GetAppData( 3025660, "config/systemprofile", 128, ) = 0, 0 bytes,
[2024-07-02 16:50:22] Setting MESA_GLSL_CACHE_DIR=C:\Program Files (x86)\Steam\steamapps\shadercache\3025660 MESA_DISK_CACHE_READ_ONLY_FOZ_DBS=steam_cache,steam_precompiled
00003015 game_obj.exe:458755 > IClientUtils::GetSteamEnvironmentForApp( 3025660, 8192, ) = 1869, 8192 bytes [45 4e 41 42 4c 45 5f 56 4b 5f 4c 41 59 45 52 5f ... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00],
00003017 game_obj.exe:458755 > IClientUtils::GetAppID( ) = 3025660,
00003018 game_obj.exe:458755 > IClientUtils::RecordSteamInterfaceCreation( "SteamUtils010", "", )
00003018 game_obj.exe:458755 > IClientUtils::GetAppID( ) = 3025660,
00003018 game_obj.exe:458755 > IClientUtils::RecordSteamInterfaceCreation( "SteamUser023", "User", )
00003019 game_obj.exe:458755 > IClientUtils::GetAppID( ) = 3025660,
00003043 game_obj.exe:458755 > IClientUser::GetSteamID( ) = [U:1:177496783],
00003048 game_obj.exe:458755 > IClientUtils::GetAppID( ) = 3025660,
00003048 game_obj.exe:458755 > IClientUtils::RecordSteamInterfaceCreation( "SteamUser023", "", )
00003049 game_obj.exe:458755 > IClientUser::GetSteamID( ) = [U:1:177496783],
[2024-07-02 16:50:22] Warming Config Cache 3025660
Warming Config Cache 3025660
[2024-07-02 16:50:22][733.235464] Adding process 9280 for gameID 3025660
[2024-07-02 16:50:22] Flushed store 'userlocal' to 'C:\Program Files (x86)\Steam\userdata\177496783\config\localconfig.vdf'
[2024-07-02 16:50:23] SSGL: change [3025660] LCT -671085920->0
CClientMusic::OnSteamPipeClosed - 458755
[2024-07-02 16:50:26] AppID 3025660 exited.
[2024-07-02 16:50:26] OnAppLifetimeNotification: appID 3025660 has no associated session information
[2024-07-02 16:50:26] [AppID 3025660] CAPIJobStoreUserStats::BInit() - no stats found, aborting
Game process removed: AppID 3025660 ""C:\Users\maman\test_steam_api\install\game_obj.exe"", ProcID 9280
[2024-07-02 16:50:26] AppID 3025660 no longer tracking PID 9280, exit code -1073741819
CClientMusic::OnAppEventStateChange 3025660 2004 4
[2024-07-02 16:50:26] Remove 3025660 from running list
[2024-07-02 16:50:26] Unknown shader cache type, ignoring.
[2024-07-02 16:50:26][737.322438] Removing process 9280 for gameID 3025660
[2024-07-02 16:50:26] Flushed store 'userlocal' to 'C:\Program Files (x86)\Steam\userdata\177496783\config\localconfig.vdf'
[2024-07-02 16:50:27] Flushed store 'userlocal' to 'C:\Program Files (x86)\Steam\userdata\177496783\config\localconfig.vdf'
] log_ipc 0
Calls over the last 13012 milliseconds:
Process Method Calls First Last
-------------------- ---------------------------------------- ---------- ---------- ----------
game_obj.exe IClientUtils::GetSteamRealm 1 3005 3005
game_obj.exe IClientUtils::GetConnectedUniverse 1 3006 3006
game_obj.exe IClientUtils::GetIPCountry 1 3006 3006
game_obj.exe IClientUtils::GetServerRealTime 1 3006 3006
game_obj.exe IClientUtils::SetAppIDForCurrentPipe 1 3007 3007
game_obj.exe IClientApps::GetAppData 1 3015 3015
game_obj.exe IClientUtils::GetSteamEnvironmentForApp 1 3015 3015
game_obj.exe IClientUtils::GetAppID 4 3017 3048
game_obj.exe IClientUtils::RecordSteamInterfaceCreati 3 3018 3048
game_obj.exe IClientUser::GetSteamID 2 3043 3049
IPC logging has been stopped
You can stop logging IPC calls using "log_ipc 0"
Solution: Use MSVC instead of MinGW