question

w1ck13 avatar image
w1ck13 asked

JNI Error (app bug): accessed stale local reference

Hi, I'm trying to access whispersync from native c++. Setting up GameCircle works so far (leaderboars/achievements). Also Whispersync is logcating: "Whispersync is ENABLED" But as soon i try to access my gamedatamap with WhispersyncClient::getGameData() the app crashes with: "JNI Error (app bug): accessed stale local reference" What am I doing wrong?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi, Can you please share the code (if possible a sample JNI project integrated with whispersync)? Are you using the latest GameCircle SDK? Thanks.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

w1ck13 avatar image
w1ck13 answered
I hope i managed creating a test project (see zip file below). The crash happens here aswell. (I downloaded my SDK 1 week ago). Im using target API 14 on linux. http://www.file-upload.net/download-9178823/TestCrash.zip.html
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

w1ck13 avatar image
w1ck13 answered
The call of AmazonGames::WhispersyncClient::getGameData(); is on line 283 in native/main.cpp.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Thanks for the sample. I have forwarded this issue to concerned team for further investigation. I will get back to your shortly.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
It looks like the issue is related to having the line "AmazonGames::WhispersyncClient::getGameData();" inside a while(1) loop. There's a good explanation of the error that they are seeing here: http://android-developers.blogspot.com/2011/11/jni-local-reference-changes-in-ics.html
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

w1ck13 avatar image
w1ck13 answered
I dont see so far why calling WhispersyncClient::getGameData() in a while(1) loop should cause a problem, since every game loop is more or less a while(1) loop. And a call during the game loop should be always expected. As i understand this article the problem lies somewhere between local and global JNI references when calling java methods. But this seems to be a bug in the wrapper to which i have no access, since the source code is already compiled to the library. Maybe it is possible to give me an example of how to call WhispersyncClient::getGameData() in a correct way during a game.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Cant you call WhispersyncClient::getGameData() once and keep it in a global variable and then use it when needed? I have asked our team to provide opinion in this regard though.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

w1ck13 avatar image
w1ck13 answered
The crash occurrs already on the first call... elsewise i could use a global variable.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Ok. I will get back to you once I hear back from the team. Thanks.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
The simplest solution would be to compile for an minimum API Level in the range 10-13. Do you need API 14? Would you be willing to drop it to 10?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.