Search code examples
c++steamsteamworks-api

Steam SDK C++ crash on GetSteamID()


on Windows 64x, using steam api version 1.60 (the last one). With the following snippet, the game crashs on the function GetSteamID

if (SteamAPI_InitEx(nullptr)) {
  if (SteamUser()) {
    printf("SteamUser() is valid.\n");
    try {
      CSteamID steamID = SteamUser()->GetSteamID();
      printf("SteamID: %llu\n", steamID.ConvertToUint64());
    } catch (const std::exception &e) {
      printf("Exception occurred: %s\n", e.what());
    }
  } else {
    printf("SteamUser() is nullptr.\n");
  }
  SteamAPI_Shutdown();
} else {
  printf("Failed to initialize Steam API.\n");
}

SteamUser() is NOT null, as I can see "SteamUser() is valid.\n". It is a valid ptr. No exception, just a crash on that function GetSteamID() With gdb, we can see in which function it crashes, which is the next function call after GetSteamID()

Thread 1 "MainThrd" received signal SIGSEGV, Segmentation fault. 0x00007ffa5a3de225 in steamclient64!Steam_NotifyMissingInterface () from C:\Program Files (x86)\Steam\steamclient64.dll

pointing my own steam client dll. It is up to date though.

I also tried using SteamAPI_Init() and SteamAPI_InitFlat() to load the API but I got the same result.

On Linux everything works fine.

Update: I followed advice from comments, I got the exact same crash behavior.

SteamErrMsg errMsg;
    if (SteamAPI_InitEx(&errMsg) == k_ESteamAPIInitResult_OK) {
        auto steamUser = SteamUser();
        if (steamUser) {
            LOG_ERROR(logger, "SteamUser() is valid.");
            try {
                CSteamID steamID = steamUser->GetSteamID();
                LOG_ERROR(logger, "SteamID: {}", steamID.ConvertToUint64());
            } catch (const std::exception &e) {
                LOG_ERROR(logger, "Exception occurred: {}", e.what());
            }
        } else {
            LOG_ERROR(logger, "SteamUser() is nullptr.");
        }
        SteamAPI_Shutdown();
    } else {
        LOG_ERROR(logger, "Failed to initialize Steam API.");
    }

Solution

  • Solution: Using MSVC instead of MinGW resolved the problem. steam_api.dll was probably built with MSVC, using another compiler will cause intern bugs.