DJPJ
DJPJ

Reputation: 349

Google Play Services Saved Game Snapshot crash on readfully()

I have spent days trying to work out the cause of this crash in the Google Play Services Saved Game code from a tester's device and have no idea what else to try as it works on all three of my devices. The crash that occurs is:

java.lang.NullPointerException: Must provide a previously opened Snapshot

when I try and call

snapshot.readFully();

even though the snapshot has been opened and return code checked, and checked to see if it is null. Here is the code path leading up to the crash, with non-executed sections removed for brevity:

public void LoadSnapshot()
{
    AsyncTask<Void, Void, SNAPSHOT_ASYNC_RESULT> task = new AsyncTask<Void, Void, SNAPSHOT_ASYNC_RESULT>() 
    {
        @Override
        protected SNAPSHOT_ASYNC_RESULT doInBackground(Void... params) 
        {
            if (isSignedIn())
            {
                Snapshots.OpenSnapshotResult result = Games.Snapshots.open(getApiClient(), "MySnapshot", true).await();
                int status = result.getStatus().getStatusCode();
                DebugLog("Snapshot Load Open result code: " + status);

                if (status == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT)
                {
                    Snapshot snapshot           = result.getSnapshot();
                    Snapshot conflictSnapshot   = result.getConflictingSnapshot();

                    //write both conflicted files so we can merge them
                    if (snapshot != null && conflictSnapshot != null)
                    {
                        byte[] ssdata = snapshot.readFully();       //CRASH HERE!

                        ...

                    }

                    ...
                }
             }
         }
     }

     task.execute();
} 

I get similar crashes from the same device when simply saving sometimes with .open() followed by .writebytes().

It is making the entire game unstable and I need to get this fixed somehow. Any help or ideas would be much appreciated.

All I can think is that because it's running on a background thread in an AsyncTask something bad has happened in between opening the snapshot and trying to read/write it on this device. According to the tester is crashes 'most' of the time.

Upvotes: 0

Views: 1011

Answers (2)

DJPJ
DJPJ

Reputation: 349

I solved this eventually by only allowing one Async operation at a time, as I was previously allowing a concurrent save and load of the same snapshot.

I also wrapped the readFully() inside a try/catch for safety.

Upvotes: 1

Scumble373
Scumble373

Reputation: 227

I'm working on this as well. I'm looking at the documentation now, and it has this to say about the function: readFully()

Read the contents of a snapshot.

If this snapshot was not opened via open(GoogleApiClient, SnapshotMetadata), or if the contents have already been committed via commitAndClose(GoogleApiClient, Snapshot, SnapshotMetadataChange) this method will throw an exception.

Returns The bytes of the snapshot contents. Throws IOException if reading the snapshot failed.

Are you sure that the snapshot has been opened and committed correctly?

Upvotes: 0

Related Questions