googlevr / gvr-unity-sdk

Google VR SDK for Unity
http://developers.google.com/vr/unity/
Other
2.71k stars 1.09k forks source link

Unity 5.3.1f / SDK 0.6 - Crash after suspend / Timeout on quit #137

Closed noemis84 closed 8 years ago

noemis84 commented 8 years ago

This post some problems already discussed in this thread: https://github.com/googlesamples/cardboard-unity/issues/116

Problem 1 - Crash after app pauses After the following simple steps the app crashes always:

on Samsung s6

no console output (using "adb logcat -s Unity")

Any ideas how to create an app with cardboard sdk + unity, which is able to go to system ui and back without crash?

Problem 2 To solve the first problem I would like to make a simple quit. Like "quit on suspend" does on IOS. The following code should do this on android:

void OnApplicationPause(bool pauseStatus) {
        if (pauseStatus) {
            Debug.Log("quit app because resume caused errors");
            Application.Quit();         
        }
    }

but i just get this from the console:

(Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Cardboard audio system is shutdown.

(Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Exception calling method onPause: UnityEngine.AndroidJavaException: java.lang.IllegalArgumentException: Receiver not registered: com.google.vr.cardboard.NFCUtils$1@1f9de38
java.lang.IllegalArgumentException: Receiver not registered: com.google.vr.cardboard.NFCUtils$1@1f9de38
     at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:871)
     at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:2091)
     at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:529)
     at com.google.vr.cardboard.NFCUtils.onPause(NFCUtils.java:71)
     at com.google.vr.platform.unity.UnityVrActivityListener.onPause(UnityVrActivityListener.java:133)
     at com.unity3d.player.UnityPlayer.nativeDone(Native Method)
     at com.unity3d.player.UnityPlayer.f(Unknown Source)
     at com.unity3d.player.UnityPlayer.h(Unknown Source)
     at com.unity3d.player.UnityPlayer$18.run(Unknown Source)
     at com.unity3d.player.UnityPlayer.executeGLThreadJobs(Unknown Source)
     at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
  at UnityEn
Timeout while trying to pause the Unity Engine.

After waiting 3 months for an update and having the same serious problems is disappointing. I hope either there is a solution or someone show me my mistakes...

ognjenmarcheta commented 8 years ago

I just tried to recreate that problem and i didn't get that weird crash. Tested on Nexus 6, Nexus 7, Nextbook 8, Xperia Z. It might be only happening to Samsung S6 or generally Samsung devices, because I also had some problems before on Samsung S4 and those problems were not happening on my other devices.

smdol commented 8 years ago

I'll check with QA but I'm pretty sure they tested this scenario on an S6. Thanks for the stack trace! It will be helpful. Do you have NFC enabled or disabled on your phone?

noemis84 commented 8 years ago

I updated my Java JDK, reinstalled android sdk, tried building with MacOSX, but it was always possible to crash the app within 30 seconds...

NFC is disabled.

here is a short video showing the crash... (left side phone held in portrait, right side in landscape - the default orientation via unity is always landscape left): https://www.dropbox.com/s/yfaunfxnzj1q3zx/crashVideo01.mp4?dl=0

app builded from this (nearly empty) project: https://www.dropbox.com/s/89c7ux66wv1ntik/cbTest.zip?dl=0

Still hoping that it's my fault and I'm blind after having this error with the older sdk version.

noemis84 commented 8 years ago

It also crashes on a One Plus X and Moto X 2nd Gen.

smdol commented 8 years ago

Can you try a quick experiment? Remove the CardboardAudioListener from the Cardboard Main prefab. Does the crash still happen?

smdol commented 8 years ago

OK, we've narrowed down this crash (your Problem 1) to the audio system in Unity 5.2+, which has a bug in it that causes exactly this problem. See:

http://forum.unity3d.com/threads/crash-within-unity-5-1-2p3-for-2-5-of-our-android-users.377839/

for a similar report. Removing or disabling the CardboardAudioListener will prevent the crash.

smdol commented 8 years ago

Updated the SDK to disable the audio component in the prefabs. That fixes the crash in your scenes from using the new prefab.

Please note that the demo scene still has the component enabled so that it can be used to learn how to use spatialized audio, and what it sounds like in headphones.

smdol commented 8 years ago

BTW @noemis84 Thank you very much for reporting this so fast. It was very helpful in getting the fix out ASAP.

About Problem 2: I actually am not sure it is safe to quit the app during pause like that. Or at least, not with the sensor logic we are using in the SDK.

noemis84 commented 8 years ago

My first test are successful. Now I'll use and test the new sdk in our apps. Many thanks @smdol for your fast reaction and of course the solution... it seems, we can start in a stable VR year :+1: - i'll close this issue for now and hope never have to reopen again ;)