4

So the code that I've been using to get a user's Steam ID is:

CSteamID uid = SteamUser()->GetSteamID();
uint64 pid = uid.ConvertToUint64();
std::ostringstream sin;
sin << pid;
std::string s = sin.str();
return s.c_str();

This works just fine, but when a user is not logged into Steam, this crashes.

Access violation - code c0000005 (first/second chance not available)


Does Steam provide a function that I can use to check if the user is logged in before running code that depends on the user being logged in? Or is there some sort of try/catch block I can use here to make sure that this does not break and return false if the user is not logged in?

Liftoff
  • 24,717
  • 13
  • 66
  • 119

1 Answers1

1

Thanks to @Lightning Racis in Orbit. A simple nullptr check fixed it.

if(SteamUser() == nullptr)
    return false;
Community
  • 1
  • 1
Liftoff
  • 24,717
  • 13
  • 66
  • 119