Steamworks checking if a user is logged in

倾然丶 夕夏残阳落幕 提交于 2019-12-07 11:04:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!