MrStahlfelge / gdx-gamesvcs

Easy integration of gameservices in your libGDX game: Google Play Games, Apple Game Center, Amazon GameCircle and more
Apache License 2.0
113 stars 20 forks source link

GPGS Android: Cloud Save - Gamestate Not Null? #25

Closed manutyagi01 closed 6 years ago

manutyagi01 commented 6 years ago

I am having another issue which you may have a better understanding of, even when all snapshots are deleted from google play services I keep getting an object back of length 0 when calling gsClient.loadGameState().....

Steps: -call gsClient.deleteGameState() on desktop, exit app -call gsClient.loadGameState() multiple times on desktop always returning null which is ok, exit app -call gsClient.loadGameState() on android first call returns null all following calls return an array with length 0, exit app -call gsClient.loadGameState() on desktop again and return is an array with length 0

very strange as I am not saving anything at all, maybe I am missing something?

public void loadSnapshot(){

      if(gsClient.isFeatureSupported(GameServiceFeature.GameStateStorage)) {

         gsClient.loadGameState("test", this);
      }
      else{
         Gdx.app.error("loadSnapshot: ", "GameStateStorage not supported by client");
      }
   }
   @Override
   public void gsGameStateLoaded(byte[] gameState) {

      if(gameState != null){

         Gdx.app.error("onGameStateLoaded", "gamestate size is =" + gameState.length);
      }
      else{

         Gdx.app.error("onGameStateLoaded", "gamestate is null" );
      }

   }

UPDATED: From lidgdx forum pm discussion with MrStahlfelge:

" It is probably because Android's GPGS gamestate creates a subdirectory causing the desktop implementation to return a 0-sized array (because there is something but no file)."

I guess the issue still remains that on android platform the returned value is not consistent with what is expected and the data can be null or invalid/reference to some empty object....?

MrStahlfelge commented 6 years ago

Check the on null or empty. From the JavaDoc:

gameState - null if loading failed

When the load did not fail, but there is nothing to load, an empty array is allowed.