Skip to content

Commit

Permalink
Fix achievement ReportProgress null pointer exception
Browse files Browse the repository at this point in the history
  • Loading branch information
olehkuznetsov committed May 3, 2019
1 parent 324ce31 commit e8f508b
Showing 1 changed file with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -659,14 +659,12 @@ public string GetUserImageUrl()
/// </param>
public void ReportProgress(string achievementID, double progress, Action<bool> callback)
{
callback = ToOnGameThread(callback);
if (!IsAuthenticated())
{
GooglePlayGames.OurUtils.Logger.e(
"ReportProgress can only be called after authentication.");
if (callback != null)
{
callback.Invoke(false);
}
callback.Invoke(false);

return;
}
Expand All @@ -686,6 +684,12 @@ public void ReportProgress(string achievementID, double progress, Action<bool> c

mClient.LoadAchievements(ach =>
{
if (ach == null)
{
GooglePlayGames.OurUtils.Logger.e("Unable to load achievements");
callback.Invoke(false);
return;
}
for (int i = 0; i < ach.Length; i++)
{
if (ach[i].Id == achievementID)
Expand Down Expand Up @@ -717,22 +721,16 @@ public void ReportProgress(string achievementID, double progress, Action<bool> c
{
// not enough to unlock
GooglePlayGames.OurUtils.Logger.d("Progress " + progress + " not enough to unlock non-incremental achievement.");
if (callback != null)
{
callback.Invoke(false);
}
callback.Invoke(false);
}
}
return;
}
}
// Achievement not found
if (callback != null)
{
GooglePlayGames.OurUtils.Logger.e("Unable to locate achievement " + achievementID);
callback.Invoke(false);
}
GooglePlayGames.OurUtils.Logger.e("Unable to locate achievement " + achievementID);
callback.Invoke(false);
});
}

Expand Down Expand Up @@ -1397,6 +1395,18 @@ private string MapId(string id)

return id;
}

private static Action<T> ToOnGameThread<T>(Action<T> toConvert)
{
if (toConvert == null)
{
return delegate
{
};
}

return (val) => PlayGamesHelperObject.RunOnGameThread(() => toConvert(val));
}
}
}
#endif

0 comments on commit e8f508b

Please sign in to comment.