Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot saving is not working sometimes #168

Closed
Motoban opened this issue Sep 29, 2015 · 4 comments
Closed

Snapshot saving is not working sometimes #168

Motoban opened this issue Sep 29, 2015 · 4 comments

Comments

@Motoban
Copy link

Motoban commented Sep 29, 2015

I'm trying to sync data between two devices using Saved Games. Yesterday all was working fine.

Today synching is working in one direction only (from Device1 to Device2). That is, when I save new data on Device1, I see it on Device2. But when I save data on Device2, I don't see it neither on Device1 nor on Device2! Yes, it's very strange that Games.Snapshots.commitAndClose() on Device2 returns OK, but immediately after that Games.Snapshots.open() on on Device2 returns old (not updated) data. Below is log from Device 2 (old data on server was 010101):

SAVE: Data=010000
SAVE: OK
READ: Data=010000 time=1443521755988 pending=true
READ: Data=010101 time=1443521755988 pending=false
READ: Data=010101 time=1443521755988 pending=false

I tried many times without success. Then, after one hour, a single save was successful:

SAVE: Data=010000
SAVE: OK
READ: Data=010000 time=1443524061900 pending=true
READ: Data=010000 time=1443524061900 pending=false
READ: Data=010000 time=1443524061900 pending=false
READ: Data=010000 time=1443524061900 pending=false
READ: Data=010000 time=1443524061900 pending=false

And now saving is not working again, but only on Device 2 (On Device 1 all is working fine). It seems that Games.Snapshots.commitAndClose() sometimes doesn't update data for some reason, but returns OK.

Some additional informtaion:

  • Device1 is Samsung Galaxy S3, Device2 is Acer Iconia Tab.
  • Both have the latest Google Play Games installed from Google Play, and both are using the latest revision 27 of Google Play Services Library for Android.
  • I'm using test account configured on Google Play Developer Console.
  • Yesterday I used Games.Snapshots.resolveConflict a few times

UPDATE:
I just found similar issue report here:
http://forum.unity3d.com/threads/google-saved-games-service-commitupdate-issue.318452

Below is my code:

        loadButton.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View vw) {
            android.os.AsyncTask.execute(new Runnable() {
              public void run() {
                try {    
                  GoogleApiClient client = mGamesHelper.getApiClient();
                  if(client == null)
                    return;

                  Snapshots.OpenSnapshotResult result = Games.Snapshots.open(client, SAVE_GAME_NAME, true, Snapshots.RESOLUTION_POLICY_MANUAL).await();
                  int status = result.getStatus().getStatusCode();

                  if (result.getStatus().isSuccess())
                  {
                    Snapshot snapshot = result.getSnapshot();

                    final byte[] localData = snapshot.getSnapshotContents().readFully();
                    if(localData.length == 3) {
                      activity.runOnUiThread(new Runnable() {
                        public void run() {
                          chk1.setChecked(localData[0] != 0);
                          chk2.setChecked(localData[1] != 0);
                          chk3.setChecked(localData[2] != 0);
                        }
                      });
                    }

                    SnapshotMetadata metadata = snapshot.getMetadata();
                    Log.i("CocosAndroid", "READ: status=" + status + " Data= " + BufToStr(localData) + 
                      " time=" + metadata.getLastModifiedTimestamp() + " pending=" + metadata.hasChangePending());
                  } 
                  else
                  if(status == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT)
                  {
                    Snapshot snapshot1 = result.getSnapshot();
                    Snapshot snapshot2 = result.getConflictingSnapshot();
                    byte[] data1 = snapshot1.getSnapshotContents().readFully();
                    byte[] data2 = snapshot2.getSnapshotContents().readFully();

                    Log.i("CocosAndroid", "READ: Conflict on data load, conflictID=" + result.getConflictId() + " data1=" + BufToStr(data1) + " data2=" + BufToStr(data2));
                  }
                  else
                  {
                    Log.i("CocosAndroid", "READ: Error while opening cloud data: " + result.getStatus().getStatusCode());
                  }
                } catch (Exception e) {
                  Log.i("CocosAndroid", "READ: EXCEPTION " + e.getMessage());
                }
              }
            });          
          }
        });

        saveButton.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View vw) {                
            android.os.AsyncTask.execute(new Runnable() {
              public void run() {
                try {    
                  GoogleApiClient client = mGamesHelper.getApiClient();
                  if(client == null)
                    return;

                  Snapshots.OpenSnapshotResult result = Games.Snapshots.open(client, SAVE_GAME_NAME, true, Snapshots.RESOLUTION_POLICY_MANUAL).await();

                  if (result.getStatus().isSuccess())
                  {
                    byte[] data = new byte[3];
                    data[0] = (byte)(chk1.isChecked() ? 1 : 0);
                    data[1] = (byte)(chk2.isChecked() ? 1 : 0);
                    data[2] = (byte)(chk3.isChecked() ? 1 : 0);

                    Snapshot snapshot = result.getSnapshot();
                    snapshot.getSnapshotContents().writeBytes(data);
                    Log.i("CocosAndroid", "SAVE: open status=" + result.getStatus().getStatusCode() + " Data=" + BufToStr(data));

                    Snapshots.CommitSnapshotResult commitResult = 
                      Games.Snapshots.commitAndClose(client, snapshot, SnapshotMetadataChange.EMPTY_CHANGE).await();
                    if(commitResult.getStatus().isSuccess())
                      Log.i("CocosAndroid", "SAVE: OK=" + commitResult.getStatus().getStatusCode());
                    else
                      Log.i("CocosAndroid", "SAVE: failed: " + commitResult.getStatus().getStatusCode());
                  }
                  else
                  {
                    Log.i("CocosAndroid", "SAVE: Error while opening cloud data: " + result.getStatus().getStatusCode());
                  }            
                } catch (Exception e) {
                  Log.i("CocosAndroid", "SAVE: EXCEPTION " + e.getMessage());
                }
              }  
            });          
          }
        });
@teemukorh
Copy link

We have been experiencing the same issue some months already..

It's also reported here: #139

@claywilkinson
Copy link
Contributor

Can you provide logs of when saving (when it seems like it is not saving the data)? If they are long, you can use a Gist. Does the cross-device save/load eventually sync up? There can be some delay since the data needs to travel over the internet, be persisted, and then go back.

@teemukorh
Copy link

I can get the logs next week. The problem is that after writing, reading back the data even to the same device gives the old data back. Only the modified timestamp seems to be correct. It doesn't report any conflicts or errors. In our case :)

@mwgray
Copy link
Contributor

mwgray commented Jan 3, 2018

Looks like #139 was closed due to lack of response and updated code, closing this as well.

@mwgray mwgray closed this as completed Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants