Unity3D for Android: “JNI ERROR (app bug): attempt to use stale global reference” with Incorrect Use of Prime31’s Social Networking Plugin

I was porting a Unity3D-built iOS game to Android the other day, while using the awesome Social Networking plugin from Prime31, and got this fun Java error:

E/dalvikvm( 5539): JNI ERROR (app bug): attempt to use stale global reference 0x32
E/dalvikvm( 5539): VM aborting
F/libc    ( 5539): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 5583 (UnityMain)
... 

The above error crashed my app consistently.

I was lucky in this case because I was fairly sure where it’s coming from, suspecting an unnecessary call to FacebookAndroid.logout() inside a check for !FacebookAndroid.isSessionValid() check. Not my proudest coding moment, for sure.

Once I put a Debug.Log() right before the FacebookAndroid.logout() call and right after. The error changed to… or perhaps a new error started showing up around the same place in the debug log:

W/dalvikvm( 2910): threadid=9: thread exiting with uncaught exception (group=0x4001d5a0)
E/AndroidRuntime( 2910): FATAL EXCEPTION: GLThread 10
E/AndroidRuntime( 2910): java.lang.NullPointerException
E/AndroidRuntime( 2910): 	at com.prime31.FacebookPlugin.logout(FacebookPlugin.java:187)
E/AndroidRuntime( 2910): 	at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
E/AndroidRuntime( 2910): 	at com.unity3d.player.UnityPlayer.onDrawFrame(Unknown Source)
E/AndroidRuntime( 2910): 	at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
E/AndroidRuntime( 2910): 	at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
W/ActivityManager( 1323):   Force finishing activity com.companyName.MyBundleIDHere/com.unity3d.player.UnityPlayerNativeActivity

The app stopped crashing but the java.lang.NullPointerException didn’t go away either. Still looking into it.

NetStream.Play.StreamNotFound Error and AS3.0 Video Player with Facebook CDN mp4 Files

While coding a Flash video player for an iFrame-based mostly-HTML Facebook app a .NET / Front End developer & I ran into this annoying problem.

When we tried to load videos stored in via a Facebook account (in mp4 format) on an Akamai (or competitor’s) CDN server (with server url similar to http://video.ak.fbcdn.net) into our custom progressive download video player kept giving us the “NetStream.Play.StreamNotFound” error.

We tried everything from looking at HTTP Headers, to finding an Adobe Employee’s post on Adobe forums that said this might not be possible (with Strobe Media Player & Facebook CDN video) to considering alternative hosting. Googling didn’t reveal too many results on this specific issue. This one was perhaps the most informative.

In the end, the .NET / Javascript developer I was working with decided to try URL encoding the string that was passed to the video player via a FlashVar. That fixed the problem!

The best part is that now, we can meet our needs AND avoid having to figure out an alternative hosting solution.