Steamworks检查用户是否登录 [英] Steamworks checking if a user is logged in
问题描述
所以我一直用来获取用户的Steam ID的代码是:
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();
这种方法很好,但是当用户没有登录Steam时, >
This works just fine, but when a user is not logged into Steam, this crashes.
访问违规 - 代码c0000005(第一/第二次机会不可用)
Access violation - code c0000005 (first/second chance not available)
Steam是否提供了一个函数,可以用来检查用户是否在运行依赖于登录用户的代码之前登录?或者是有一些try / catch块我可以在这里使用,以确保这不会破坏,如果用户没有登录返回false。
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?
推荐答案
感谢 @Lightning Racis in Orbit 。一个简单的nullptr检查固定它。
Thanks to @Lightning Racis in Orbit. A simple nullptr check fixed it.
if(SteamUser() == nullptr)
return false;
这篇关于Steamworks检查用户是否登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!