[RESOLVED] GPGS java.lang.IllgalStateException - is there anything I can do to avoid this error?

When a user creates a match game via Google Play Game Services and then start the game before an opponent joins the game, it crashes the app with java.lang.IllgalStateException runtime error.  I’d like to know how we may prevent this from happening.

Here’s how to reproduce this error:

  1.  Create a match game, which brings up GPGS screen (a generic screen that comes up for any GPGS multiplayer games.)

  2.  On this screen, pick Auto-pick player and tap on “Play”.

  3.  Screen changes to “Waiting for auto-match” screen (another generic screen that comes up for any GPGS multiplayer games.)

  4.  On this waiting screen, there is a drop down menu on upper right corner (with three dots), which provides “Start playing” and “Leave room” option.  If I can hide “Start playing” option, it would prevent this error from happening all together.  However, if I can’t hide it and if the “Start playing” is tapped while waiting for an opponent to join the game, app crashes with the runtime error:  java.lang.IllgalStateException: Not connected.  Call connect() and wait for onConnected() to be called.

As far as I am aware, this GPGS screen is beyond my control.  And if so, are all GPGS multiplayer games doomed to crash like this when they are built with Corona SDK?  If I am mistaken, and Corona SDK built apps can handle this without causing any runtime errors, I’d so like to know how.  Please help!

Naomi

I had a thought.  In the waitingRoomListener function (with “waitingRoom” as its event.type), when the event.data.phase changes to “start” but event.data[1] is nil, if I don’t launch the game, maybe it would prevent this error all together?  It may very well be worth investigating further.
 

Naomi

It worked.  It won’t start the game and cause the error.  It now simply closes the waitingRoom screen when I tap on “Start playing.”  Honestly, it shouldn’t show “Start playing” when no other player joins the game.  It makes no sense to have a option to “start playing” when it can’t start playing.  

Anyhow,  all I have to do now is to make the screen go back to match game menu screen.  It may not hurt to add an alert message for the users, letting them know that the game cannot be started without an opponent.

Naomi 

I had a thought.  In the waitingRoomListener function (with “waitingRoom” as its event.type), when the event.data.phase changes to “start” but event.data[1] is nil, if I don’t launch the game, maybe it would prevent this error all together?  It may very well be worth investigating further.
 

Naomi

It worked.  It won’t start the game and cause the error.  It now simply closes the waitingRoom screen when I tap on “Start playing.”  Honestly, it shouldn’t show “Start playing” when no other player joins the game.  It makes no sense to have a option to “start playing” when it can’t start playing.  

Anyhow,  all I have to do now is to make the screen go back to match game menu screen.  It may not hurt to add an alert message for the users, letting them know that the game cannot be started without an opponent.

Naomi