playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.46k stars 965 forks source link

Error in fetching scores from leaderboard #1107

Open srinivaassunil opened 8 years ago

srinivaassunil commented 8 years ago

Hi there, I have 4 leader boards in my game and i wanted to fetch all current player scores and apply them locally so that scores are in sync across all devices bearing same account.When i request score from any one of the leader boards ,it is working fine but when i try to fetch them all sequentially it resulted in the following error.


04-13 11:59:08.736   536   675 W Unity   : !!! [Play Games Plugin DLL] 04/13/16 11:59:08 +05:30 WARNING: Error returned from fetch: ERROR_INTERNAL

04-13 11:59:08.736   536   675 W Unity   :  

04-13 11:59:08.736   536   675 W Unity   : (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

04-13 11:59:08.736   536   675 W Unity   : 

04-13 11:59:08.813   536   675 W Unity   : *** [Play Games Plugin DLL] 04/13/16 11:59:08 +05:30 ERROR: Error encountered executing LeaderboardManager#InternalFetchCallback. Smothering to avoid passing exception into Native: System.NullReferenceException: Object reference not set to an instance of an object

04-13 11:59:08.813   536   675 W Unity   :   at GooglePlayGamesManager+<syncScore>c__AnonStorey9E.<>m__138 (GooglePlayGames.BasicApi.LeaderboardScoreData data) [0x00000] in G:\Workspaces\sineline\SINELINE_ANDROID\3.3\Sine Line\Assets\scripts\GooglePlayGamesManager.cs:153 

04-13 11:59:08.813   536   675 W Unity   :   at GooglePlayGames.Native.PInvoke.LeaderboardManager.HandleFetch (GooglePlayGames.BasicApi.ScorePageToken token, GooglePlayGames.Native.PInvoke.FetchResponse response, System.String selfPlayerId, Int32 maxResults, System.Action`1 callback) [0x00079] in G:\Workspaces\sineline\SINELINE_ANDROID\3.3\Sine Line\Assets\GooglePlayGames\Platforms\Native\PInvoke\LeaderboardManager.cs:150 

04-13 11:59:08.813   536   675 W Unity   :   at GooglePlayGames.Native.PInvoke.LeaderboardManager+<LoadLeaderboardData>c__AnonStorey94.<>m__F1 (GooglePlayGames.Native.PInvoke.FetchRespons

This is what i did(c# code)


public string FetchFromLeaderBoard (string LID)
    {
        string res = "";
        if (Social.localUser.authenticated) {
            try {
                PlayGamesPlatform.Instance.LoadScores (
                    LID,
                    LeaderboardStart.PlayerCentered,
                    1,
                    LeaderboardCollection.Public,
                    LeaderboardTimeSpan.AllTime,
                    (LeaderboardScoreData data) => {
                        res = data.PlayerScore.formattedValue;
                        Debug.Log ("player score at `leaderboard` is  " + data.PlayerScore.formattedValue);
                    });
            } catch (Exception e) {
                Debug.Log (e.StackTrace);
            } 
        } else {

            Debug.Log ("failed to sync LB");
        }
        return res;

    }

.-----------------------------------------------------------------------------------------------------------------------------
cl_mostNearmisses = FetchFromLeaderBoard (GPG_CONSTANTS.leaderboard_most_near_misses_in_a_game);
        cl_moststreaks = FetchFromLeaderBoard (GPG_CONSTANTS.leaderboard_most_streaks_in_a_game);
        cl_total = FetchFromLeaderBoard (GPG_CONSTANTS.leaderboard_total_score);

This gives an error.Anyone could you please help!.

Thanks in Advance LOG FILE: sllog.txt

claywilkinson commented 8 years ago

Can you share an unfiltered log (this one only has the Unity category). There is an error: 11:59:09 +05:30 WARNING: Error returned from fetch: ERROR_INTERNAL In your callback, you need to check data.Valid before accessing the contents.

srinivaassunil commented 8 years ago

Thank you for responding. Here is the full log file (without filter).And one more thing only the last loadscore method is working ie. if i write four load score methods one after another to fetch score from four different leader boards only the last one is working.

Point is that I have to get all n player scores from n different leader boards .What is the best way to do it?

FULLSL_LOG.txt

claywilkinson commented 8 years ago

Thanks - I'll take a closer look.

srinivaassunil commented 8 years ago

Finally solved it

FetchScore(LID1);
FetchScore(LID2);
FetchScore(LID3);

How to solve it

 new Thread(() => FetchScore(LID1)).Start();
 new Thread(() => FetchScore(LID2)).Start();
 new Thread(() => FetchScore(LID3)).Start();
claywilkinson commented 8 years ago

Nice description of the issue and the workaround! We'll make sure to incorporate this into a future release.

srinivaassunil commented 8 years ago

Thank you @claywilkinson .