I am developing a GearVR application on Samsung Galaxy S8 in developer mode. I am not using VrAppFramework, but developing as per the VrCubeWorld_SurfaceView example. Android Studio, OVR mobile version 1.7.0, debug mode. I am having a problem with my application crashing constantly when taking the following steps:
1) Disconnect the remote by turning off bluetooth, if it's connected. The remote may need to be paired with the device first though. 2) Start the application 3) Push back button to open the return-to-oculus-menu confirmation screen 4) Select return to oculus menu. 5) Re-run the application by selecting it from the oculus menu 6) Application crashes
When returning to oculus menu after step 4, the following message is invariably printed in logcat after my application's Activity terminates:
E/ActivityThread: Activity au.com.sbs.video360.gearvr.GearVrActivity has leaked ServiceConnection com.oculus.vrapi.GearVrRemoteForBatteryWorkAround$RemoteServiceConnectionForBatteryWorkAround@6cd3897 that was originally bound here android.app.ServiceConnectionLeaked: Activity au.com.sbs.video360.gearvr.GearVrActivity has leaked ServiceConnection com.oculus.vrapi.GearVrRemoteForBatteryWorkAround$RemoteServiceConnectionForBatteryWorkAround@6cd3897 that was originally bound here at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1399) at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1294) at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1520) at android.app.ContextImpl.bindService(ContextImpl.java:1492) at android.content.ContextWrapper.bindService(ContextWrapper.java:711) at com.oculus.vrapi.GearVrRemoteForBatteryWorkAround.startRemote(GearVrRemoteForBatteryWorkAround.java:97) at com.oculus.vrapi.RemoteManager.bindInputServiceBatteryWorkAround(RemoteManager.java:137)
After step 6, the following message is printed in logcat, together with a long list printing the stack traces of each thread in the system:
JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception java.lang.IllegalArgumentException: Service not registered: com.oculus.vrapi.GearVrRemoteForBatteryWorkAround$RemoteServiceConnectionForBatteryWorkAround@6cd3897 at android.app.IServiceConnection android.app.LoadedApk.forgetServiceDispatcher(android.content.Context, android.content.ServiceConnection) (LoadedApk.java:1352) at void android.app.ContextImpl.unbindService(android.content.ServiceConnection) (ContextImpl.java:1553) at void android.content.ContextWrapper.unbindService(android.content.ServiceConnection) (ContextWrapper.java:723) at void com.oculus.vrapi.GearVrRemoteForBatteryWorkAround.stopRemote() (GearVrRemoteForBatteryWorkAround.java:115) at void com.oculus.vrapi.RemoteManager.bindInputServiceBatteryWorkAround(android.content.Context, long) (RemoteManager.java:132)
The crash seems to happen upon the first native call to java side after calling vrapi_EnterVrMode(). It can be one of my own JNI calls, or even something like vrapi_RecenterPose(). I can suppress the crash by calling ExceptionClear() after vrapi_EnterVrMode(), but then the application crashes again when I finally turn bluetooth on to connect the controller.
Note: The crash does not happen if the controller has been connected at least once during the application run. It does not seem to matter if it's connected or not upon exiting to oculus menu. The application and the remote itself work perfectly when the remote is connected.
Am I doing something wrong? Other applications don't seem to have the same problem, but this one is really hard to solve myself since the exception arises from inside the vrapi library from java side, for which the code isn't even included in the SDK. Is there a way to ensure the release of the ServiceConnection, even when vrapi "workaround" fails to do it? What triggers the ServiceConnection cleanup code execution in vrapi anyway? Is there some way to prevent it from executing?