Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

GPGS V2 – Context Error in flight mode
Started by philipp3 Dec 21 2018 04:59 AM

6 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

philipp3

[GLOBAL: userInfoPane.html]
philipp3
  • Enthusiast

  • 90 posts
  • Corona SDK

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



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,693 posts
  • Enterprise

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



[TOPIC: post.html]
#3

philipp3

[GLOBAL: userInfoPane.html]
philipp3
  • Enthusiast

  • 90 posts
  • Corona SDK

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?



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,693 posts
  • Enterprise

@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



[TOPIC: post.html]
#5

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 974 posts
  • Corona SDK

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.



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,693 posts
  • Enterprise

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



[TOPIC: post.html]
#7

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 974 posts
  • Corona SDK

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.




[topic_controls]
[/topic_controls]