googlevr / gvr-unity-sdk

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

Freezing occurs on iPhone X when switching devices #921

Closed KzKousaka closed 6 years ago

KzKousaka commented 6 years ago

Summary: When loading & switching devices on iPhone X, the main thread freezes. (not shutdown) Strangely, I checked on iPhone 6s, iPhone 5s, but it did not happen.

Found using:

Steps to reproduce the issue:

  1. setup sdks (Player Settings > XRSettings > Virtual Reality SDKs)

    1. None
    2. Cardboard
  2. Switch to cardboard by some operation.

    IEnumerator LoadCardBoard() {
        XRSettings.LoadDeviceByName("cardboard");
        yield return null;
        XRSettings.enabled = true;
    }

image

Additional comments: I seem to consume resources in libGVRSDK.a, so I did not understand the cause.

Performador commented 6 years ago

I was unable to repo this on 1.120.0, 1.130.0 and 1.140.0 (Unity 2018.1.3f1).

I triggered your code from Start function of a script attached to the camera.

rusmaxham commented 6 years ago

Are you able to reproduce this with the HelloVR sample scene?

KzKousaka commented 6 years ago

Thank you for you the reply!

Are you able to reproduce this with the HelloVR sample scene?

It works correctly. ( However, you need to specify "0: Cardboard" for "setup sdks" )

I made a simple reproduction project so please check it. https://github.com/kazu1107/cardboard-test

It worked on my friend's iPhone. but , It will not work on my iPhone.

Please watch the video, since i recorded the situation. https://www.dropbox.com/sh/votu4zjasx55wq6/AAD3G6tt5cT_eao_K_OK6FqWa?dl=0

The log at this time is as follows

Success

2018-06-11 17:31:18.809610+0900 ProductName[6121:3480774] [DYMTLInitPlatform] platform initialization successful
2018-06-11 17:31:18.880797+0900 ProductName[6121:3480644] Built from '2018.1/release' branch, Version '2018.1.3f1 (a53ad04f7c7f)', Build type 'Release', Scripting Backend 'il2cpp'
2018-06-11 17:31:18.883699+0900 ProductName[6121:3480644] -> registered mono modules 0x1018af880
-> applicationDidFinishLaunching()
2018-06-11 17:31:18.928607+0900 ProductName[6121:3480644] Metal GPU Frame Capture Enabled
2018-06-11 17:31:18.929016+0900 ProductName[6121:3480644] Metal API Validation Disabled
-> applicationDidBecomeActive()
GfxDevice: creating device client; threaded=1
Initializing Metal device caps: Apple A11 GPU
Initialize engine version: 2018.1.3f1 (a53ad04f7c7f)
UnloadTime: 2.350458 ms
2018-06-11 17:31:35.149080+0900 ProductName[6121:3480779] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
2018-06-11 17:31:35.149165+0900 ProductName[6121:3480779] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
touch
Main:Update()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

2018-06-11 17:31:37.978322+0900 ProductName[6121:3480644] INFO [vr/gvr/capi/src/gvr.cc:116] Initialized GVR version 1.120.0
[VRDevice] Successfully created device cardboard.
touch
Main:Update()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

touch
Main:Update()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

touch
Main:Update()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

Fail

2018-06-11 17:32:53.410758+0900 ProductName[1342:457938] [DYMTLInitPlatform] platform initialization successful
2018-06-11 17:32:53.463095+0900 ProductName[1342:457718] Built from '2018.1/release' branch, Version '2018.1.3f1 (a53ad04f7c7f)', Build type 'Release', Scripting Backend 'il2cpp'
2018-06-11 17:32:53.465494+0900 ProductName[1342:457718] -> registered mono modules 0x10332f880
-> applicationDidFinishLaunching()
2018-06-11 17:32:53.522930+0900 ProductName[1342:457718] Metal GPU Frame Capture Enabled
2018-06-11 17:32:53.523361+0900 ProductName[1342:457718] Metal API Validation Disabled
-> applicationDidBecomeActive()
GfxDevice: creating device client; threaded=1
Initializing Metal device caps: Apple A11 GPU
Initialize engine version: 2018.1.3f1 (a53ad04f7c7f)
UnloadTime: 2.591166 ms
touch
Main:Update()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
2018-06-11 17:33:00.279934+0900 ProductName[1342:457718] INFO [vr/gvr/capi/src/gvr.cc:116] Initialized GVR version 1.120.0
[VRDevice] Successfully created device cardboard.
2018-06-11 17:33:07.527159+0900 ProductName[1342:457929] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
2018-06-11 17:33:07.527211+0900 ProductName[1342:457929] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
2018-06-11 17:33:10.394569+0900 ProductName[1342:458045] TIC TCP Conn Failed [3:0x1c8172000]: 3:-9802 Err(-9802)

I glad when the problem is solved.

Thank you.

AntoineOctarina commented 6 years ago

Hello I have the exact same issue using :

It was also tested with the same setup on iPhone7 and it works. I did not get the chance to test it on iPhoneX.

I used the script recommended for switching modes and added a lot of yield (too many) to make sure everything had time to finish correctly.

IEnumerator SwitchToVR()
    {
        Debug.Log("Switching to VR mode");
        // Device names are lowercase, as returned by `XRSettings.supportedDevices`.
        string desiredDevice = "cardboard";

        // Some VR Devices do not support reloading when already active, see
        // https://docs.unity3d.com/ScriptReference/XR.XRSettings.LoadDeviceByName.html
        Debug.Log("Load cardboard device");
        if (string.Compare(XRSettings.loadedDeviceName, desiredDevice, true) != 0)
        {
            XRSettings.LoadDeviceByName(desiredDevice);

            // Must wait one frame after calling `XRSettings.LoadDeviceByName()`.
            yield return null;
            yield return null;
        }

        Debug.Log("Verify cardboard device is loaded");

        Debug.Log("Loaded device " + XRSettings.loadedDeviceName + ". Expected device " + desiredDevice);
        yield return null;

        yield return null;
        // Now it's ok to enable VR mode.
        Debug.Log("Enable cardboard device");
        XRSettings.enabled = true;
        ModeSwitchEnd();
    }

In the console when running the App, I get the entry "Loaded device " + XRSettings.loadedDeviceName + ". Expected device " + desiredDevice But I do not get "Enable cardboard device".

But the really weird thing is that I have a callback in my ModeSwitchEnd() function to load the scene with the player and start the video. This function seems to be called and I can hear the sound of the video. But I cannot see the video because my mode switch scene is not unloaded as it should be and it UI is taking all the screen space.

Here is a screen after freeze with console showing. https://imgur.com/bRowqZh

I am in dire need of a workaround.

AntoineOctarina commented 6 years ago

Hi,

I updated my macOS Unity to 2018.2 and reimported the googleVR unity package in the project. This solved the issue.

fredsa commented 6 years ago

This appears to be fixed in the latest Google VR SDK for Unity.

Please feel free to reopen if it still occurs with the latest SDK.