GPGS V2 – Context Error in flight mode

Hello,

I use the following lines to test the differences between gpgs and gpgs.v2:

gpgs = require( "plugin.gpgs" ) -- or gpgs = require( "plugin.gpgs.v2" ) local function loadLocalPlayerCallback(e) end function loginCallbackGpgs(event) gpgs.players.load({listener = loadLocalPlayerCallback}) end gpgs.login({userInitiated = true, listener = loginCallbackGpgs}) -- some time later: local function submitScore() if gpgs.isConnected() then print ("connected") gpgs.leaderboards.submit({leaderboardId = "xyz", score = 123}) end end

While this works in flight mode on Android with gpgs, it throws out an error when using gpgs.v2 when calling submitScore:

java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.Context android.content.ContextWrapper.getApplicationContext()’ on a null object reference

Shouldn’t gpgs.v2 be backwards compatible?

Build Version 2018.3428

I spoke with the engineer that built the plugin and he’s looking to see if he can harden the plugin and he’s trying but it’s pretty difficult. He basically said that you shouldn’t be calling submitScore() when in airplane mode. To work with leaderboards, the user needs to be logged in. Perhaps the old version of the plugin threw away data.

You might want to look at the “MoreInfo” plugin: https://marketplace.coronalabs.com/corona-plugins/more-info

It has a way to check the network status and don’t submitScore or do any game networking activity when you don’t have an internet connection.

Rob

Thanks, that’s a great hint, I always wondered how to find out if the device is in airplane mode.

So basically everyone who uses gpgs v2 should also use that plugin?

@philipp3, I think it’s safe to say that any app doing networking should check if networking is available before using it. You can choose to use the plugin, you can do native builds, and build your own calls to get networking information, or have a test that checks a high response site by opening a socket connection to a known source with a short timeout to check.

The plugin is probably the easiest approach. Just keep in mind that it just tells you if the device is connected via a method or not, it doesn’t check the quality of the network connection, nor does it check the availability of the server you’re trying to connect to.

Rob

I get a similar error after the last update. I have used Corona build 3434.

Here is the error:

Runtime Error

java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.Context com.ansca.corona.CoronaActivity.getApplicationContext()’ on a null object reference

Is there any news about this or has anybody an idea what exactly is causing this? It seems to be connected to the usage of the gpgs v2 version. For some users the error is appearing when the gpgs.init() is called and for some others when some of the other gpgs functions are called.

Are you getting this while in flight mode?

Are you checking to make sure you have a valid network connection before calling GPGS calls?

Rob

This error was also appearing in non-flight mode when accessing gpgs features. After testing different approaches I have removed the gpgs features for now, so the game is stable again. I will return to this issue in a few days.

I spoke with the engineer that built the plugin and he’s looking to see if he can harden the plugin and he’s trying but it’s pretty difficult. He basically said that you shouldn’t be calling submitScore() when in airplane mode. To work with leaderboards, the user needs to be logged in. Perhaps the old version of the plugin threw away data.

You might want to look at the “MoreInfo” plugin: https://marketplace.coronalabs.com/corona-plugins/more-info

It has a way to check the network status and don’t submitScore or do any game networking activity when you don’t have an internet connection.

Rob

Thanks, that’s a great hint, I always wondered how to find out if the device is in airplane mode.

So basically everyone who uses gpgs v2 should also use that plugin?

@philipp3, I think it’s safe to say that any app doing networking should check if networking is available before using it. You can choose to use the plugin, you can do native builds, and build your own calls to get networking information, or have a test that checks a high response site by opening a socket connection to a known source with a short timeout to check.

The plugin is probably the easiest approach. Just keep in mind that it just tells you if the device is connected via a method or not, it doesn’t check the quality of the network connection, nor does it check the availability of the server you’re trying to connect to.

Rob

I get a similar error after the last update. I have used Corona build 3434.

Here is the error:

Runtime Error

java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.Context com.ansca.corona.CoronaActivity.getApplicationContext()’ on a null object reference

Is there any news about this or has anybody an idea what exactly is causing this? It seems to be connected to the usage of the gpgs v2 version. For some users the error is appearing when the gpgs.init() is called and for some others when some of the other gpgs functions are called.

Are you getting this while in flight mode?

Are you checking to make sure you have a valid network connection before calling GPGS calls?

Rob

This error was also appearing in non-flight mode when accessing gpgs features. After testing different approaches I have removed the gpgs features for now, so the game is stable again. I will return to this issue in a few days.