问题
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?
回答1:
Thanks to @Lightning Racis in Orbit. A simple nullptr check fixed it.
if(SteamUser() == nullptr)
return false;
来源:https://stackoverflow.com/questions/29854767/steamworks-checking-if-a-user-is-logged-in