googlevr / cardboard

Open source Cardboard SDK and samples
Other
1.49k stars 256 forks source link

Issue with the new Google Cardboard XR Plugin #98

Closed lorenzofranceschi closed 4 years ago

lorenzofranceschi commented 4 years ago

I'am developing a Unity3D application and I used the Google Cardboard XR Plugin. I follow the documentation but it doesn't work. I wrote in to the Unity technologies forum but no solutions are found (https://forum.unity.com/threads/question-xr-plugin-management-initialize-on-startup.819798/).
I suppose the issue is with the DeInitializeLoader() function. The code below works when I call for the first time the function StartXR() and the function StopXR() but if I call again the StartXR() function, the app crash or doesn't change screen mode.

IEnumerator StartXR() { yield return XRGeneralSettings.Instance.Manager.InitializeLoader(); if (XRGeneralSettings.Instance.Manager.activeLoader == null) { Debug.LogError("Initializing XR Failed. Check Editor or Player log for details."); } else { Debug.Log("Starting XR..."); XRGeneralSettings.Instance.Manager.StartSubsystems(); yield return null; } }

void StopXR() { if (XRGeneralSettings.Instance.Manager.isInitializationComplete) { XRGeneralSettings.Instance.Manager.StopSubsystems(); Camera.main.ResetAspect(); XRGeneralSettings.Instance.Manager.DeinitializeLoader(); } }

Any help? Thanks in advance!

TrveFenris commented 4 years ago

What version of the Unity engine are you running? Check this issue (which is closed, sadly 🙄) where at least one user reported that a newer version of Unity solved this issue. I still need to try this by myself, will update this thread if I'm successful.

lorenzofranceschi commented 4 years ago

I downloaded the 2020.3.1f. But now I've some problems with some grandle errors. I'll fix it and I'll tell you if this version works. Have some news?

TrveFenris commented 4 years ago

Also having issues with Gradle, upgraded from 2019.4.8f1 to 2020.1.3f1. Keep me posted too! I've been trying to enable Android X via a gradle template but then I get errors with some other libraries which seem to be not compatible with Jetifier+Android X.

FWIW I'm using Firebase Auth and the Cardboard XR plugin in my project.

lorenzofranceschi commented 4 years ago

I only use Cardboard XR Plugin but it is still not working. Keep in touch to find a solution!

TrveFenris commented 4 years ago

Sorted out the issues that I was having with incompatible libs by adding these to the Gradle dependencies:

implementation 'com.google.android.material:material:1.1.0' implementation 'com.google.android.gms:play-services-vision:15.0.2' implementation 'com.google.protobuf:protobuf-lite:3.0.0'

Then I had issues with JAVA_HOME (seems like Unity 2020 is a bit buggy...) which I solved by re-checking these:

image

Then! Since I was using Firebase, I had to fix an issue with that (again, thanks v2020 😆).

Succesfully built the app but the crash while unloading and re-initializing the XR manager persists 👎 . What is curious is that you can stop the subsystems (instead of deinitializing/unloading) and that works well to go back to 2D mode, but then if you change apps and go back to your Unity app the VR mode kicks in again and messes things up.

lorenzofranceschi commented 4 years ago

@TrveFenris Does the Cardboard XR Plugin works now?

kebin628 commented 4 years ago

I have same issue! My application must often switch between VR mode and Normal mode, therefore this switching problem is very critical issue.

[Environment] Unity version: Unity 2019.4.9f1 and Unity 2020.1.3f Google Cardboard XR Plugin for Unity(get from Unity Package Manager, UPM): 1.2.0 Checked Device: Pixel 4a (Android 10)

[Test Check Process]

  1. Get plugin by UPM.
  2. Create scene.
  3. Added VR and Normal view switch component in the scene.
  4. Checked Cardboard XR Plugin on XR Plug-in Management setting.
  5. Build, then switch VR and Normal mode.

Switch process is same of lorenzofranceschi's script.

[Results] Both Unity versions are same result.

Initialize XR on Startup: true

  1. VR view(startup)
  2. switch to Normal view.
  3. switch to VR view, but crashed.

Initialize XR on Startup: false

  1. Normal view(startup)
  2. switch to VR view
  3. switch to Normal view
  4. switch to VR view, but crashed.

This crash is caused by SIGSEGV, null pointer dereference, but the crashlog is veeeeery long, finally I can't find out why this crash happend...

I think this problem is caused by starting XR mode(ex. InitializeLoader) after closing VR mode(ex. DeinitializeLoader).

Arne-van-der-Lei commented 4 years ago

Hay just wanted to confirm that this is a pressing matter. We used to be able to do this in the daydream SDK. Could we have any update on this from google?

TrveFenris commented 4 years ago

@lorenzofranceschi didn't have the time to retest with the new version of the plugin, will probably do so today/tomorrow and post again if it works. Were you able to sort out your Gradle issues? I feel like Unity v2020 introduced quite a few bugs... I'll keep working on v2019.

sammyvrmadman commented 4 years ago

Same crash here when initializing for a second time. The same code works fine for iOS though. Wondering if this issue is on the roadmap to be fixed in the near future.

julien-tamade commented 4 years ago

I'm running into an issue where even initializing and then starting subsystems, the VR doesn't start. Anybody know how to fix this?

dletozeun commented 4 years ago

Hello,

I have reproduced the crash on Unity 2019.4.11f1. After some debugging in the native cardboard unity plugin, I have found a quick fix and rebuilt the sdk.aar file and repackaged the whole Unity package to replace the obsolete Play Service resolver by External Dependency Manager for Unity

This fixes the crash on Android on second activation of VR as well as AndroidX compatibilites issues (especially when you have other SDKs involved in your Unity project). The Dependencies.xml file in the Unity package downloads the required dependencies and you don't have to touch gradle config anymore.

Here a temporary Unity package fixing the issue: GoogleCardboardXR.zip

You'll need to install the External Dependency Manager for Unity and remove the Google Cardboard XR package installed from the Unity package manager first.

It has been tested as well on iOS. The only unrelated issue on iOS I still have is random (rare) crashes sometimes between VR activations in OpenGL ES code which is obsolete...

sammyvrmadman commented 4 years ago

Hello,

I have reproduced the crash on Unity 2019.4.11f1. After some debugging in the native cardboard unity plugin, I have found a quick fix and rebuilt the sdk.aar file and repackaged the whole Unity package to replace the obsolete Play Service resolver by External Dependency Manager for Unity

This fixes the crash on Android on second activation of VR as well as AndroidX compatibilites issues (especially when you have other SDKs involved in your Unity project). The Dependencies.xml file in the Unity package downloads the required dependencies and you don't have to touch gradle config anymore.

Here a temporary Unity package fixing the issue: GoogleCardboardXR.zip

You'll need to install the External Dependency Manager for Unity and remove the Google Cardboard XR package installed from the Unity package manager first.

It has been tested as well on iOS. The only unrelated issue on iOS I still have is random (rare) crashes sometimes between VR activations in OpenGL ES code which is obsolete...

Awesome that totally works thanks for the fix!!

mjcipriano commented 4 years ago

Hello,

I have reproduced the crash on Unity 2019.4.11f1. After some debugging in the native cardboard unity plugin, I have found a quick fix and rebuilt the sdk.aar file and repackaged the whole Unity package to replace the obsolete Play Service resolver by External Dependency Manager for Unity

This fixes the crash on Android on second activation of VR as well as AndroidX compatibilites issues (especially when you have other SDKs involved in your Unity project). The Dependencies.xml file in the Unity package downloads the required dependencies and you don't have to touch gradle config anymore.

Here a temporary Unity package fixing the issue: GoogleCardboardXR.zip

You'll need to install the External Dependency Manager for Unity and remove the Google Cardboard XR package installed from the Unity package manager first.

It has been tested as well on iOS. The only unrelated issue on iOS I still have is random (rare) crashes sometimes between VR activations in OpenGL ES code which is obsolete...

So I tried this with Unity 2019.3 and it works using the old XR system, but when I do add this in Unity 2020, I get an option for Google Cardboard under the selection list for XR plugin-in Management/Android, but I click on it and it does not make a checkmark, it just flashes "Installing packages" then does not leave the Plug-in Providers checked. Am I missing something simple here, I'm kinda new to this.

dletozeun commented 4 years ago

I have already this issue in Unity 2019.4.x as well and simply had to restart the editor. It looks like it is a Unity editor bug and it is unrelated to the Cardboard SDK. Maybe restart the XR Plugin Management package if the problem persists.

LukasRoper commented 4 years ago

Hello, I have reproduced the crash on Unity 2019.4.11f1. After some debugging in the native cardboard unity plugin, I have found a quick fix and rebuilt the sdk.aar file and repackaged the whole Unity package to replace the obsolete Play Service resolver by External Dependency Manager for Unity This fixes the crash on Android on second activation of VR as well as AndroidX compatibilites issues (especially when you have other SDKs involved in your Unity project). The Dependencies.xml file in the Unity package downloads the required dependencies and you don't have to touch gradle config anymore. Here a temporary Unity package fixing the issue: GoogleCardboardXR.zip You'll need to install the External Dependency Manager for Unity and remove the Google Cardboard XR package installed from the Unity package manager first. It has been tested as well on iOS. The only unrelated issue on iOS I still have is random (rare) crashes sometimes between VR activations in OpenGL ES code which is obsolete...

So I tried this with Unity 2019.3 and it works using the old XR system, but when I do add this in Unity 2020, I get an option for Google Cardboard under the selection list for XR plugin-in Management/Android, but I click on it and it does not make a checkmark, it just flashes "Installing packages" then does not leave the Plug-in Providers checked. Am I missing something simple here, I'm kinda new to this.

I'm having this same issue. I seem to get this when I tick it:

XR Plug-in Management error. Failure reason: Error Message: Unable to add package [com.google.xr.cardboard]:

Tried the process a couple of times and doesn't seem to work. Not sure if it's meant to be done in a very specific order?

LukasRoper commented 4 years ago

I did get this working through a

Hello, I have reproduced the crash on Unity 2019.4.11f1. After some debugging in the native cardboard unity plugin, I have found a quick fix and rebuilt the sdk.aar file and repackaged the whole Unity package to replace the obsolete Play Service resolver by External Dependency Manager for Unity This fixes the crash on Android on second activation of VR as well as AndroidX compatibilites issues (especially when you have other SDKs involved in your Unity project). The Dependencies.xml file in the Unity package downloads the required dependencies and you don't have to touch gradle config anymore. Here a temporary Unity package fixing the issue: GoogleCardboardXR.zip You'll need to install the External Dependency Manager for Unity and remove the Google Cardboard XR package installed from the Unity package manager first. It has been tested as well on iOS. The only unrelated issue on iOS I still have is random (rare) crashes sometimes between VR activations in OpenGL ES code which is obsolete...

So I tried this with Unity 2019.3 and it works using the old XR system, but when I do add this in Unity 2020, I get an option for Google Cardboard under the selection list for XR plugin-in Management/Android, but I click on it and it does not make a checkmark, it just flashes "Installing packages" then does not leave the Plug-in Providers checked. Am I missing something simple here, I'm kinda new to this.

I'm having this same issue. I seem to get this when I tick it:

XR Plug-in Management error. Failure reason: Error Message: Unable to add package [com.google.xr.cardboard]:

Tried the process a couple of times and doesn't seem to work. Not sure if it's meant to be done in a very specific order?

I ended up working out a workaround for this. Had to essentially make my own package which I hosted somewhere and then merged the preexisting plugin with the amended version. Then seemed ok to add Cardboard support in the XR Plugin Management area and could build.

dletozeun commented 4 years ago

Indeed I have reproduced the error on Unity 2019 or 2020 in a new Unity project.

The GoogleCardboard.zip file in my previous post is actually a bad idea. As it doesn't install through the package manager, enabling Cardboard XR Plugin in Player Settings > XR Plug-in Management cause the error:

XR Plug-in Management error. Failure reason: Error Message: Unable to add package [com.google.xr.cardboard]

Instead I have forked Google cardboard-xr-plugin you originally install from the git repo and patched the sdk.aar file.

So by the time, Google fixes its own repo, you can add the Unity package from this url instead:

https://github.com/dletozeun/cardboard-xr-plugin.git

Hopefully, you should be able from there to check Cardboard XR Plugin this time.

dletozeun commented 4 years ago

I ended up working out a workaround for this. Had to essentially make my own package which I hosted somewhere and then merged the preexisting plugin with the amended version. Then seemed ok to add Cardboard support in the XR Plugin Management area and could build.

Sorry, our messages crossed and this is it indeed. I have submitted a PR there: https://github.com/googlevr/cardboard-xr-plugin/pull/12

mjcipriano commented 4 years ago

Indeed I have reproduced the error on Unity 2019 or 2020 in a new Unity project.

The GoogleCardboard.zip file in my previous post is actually a bad idea. As it doesn't install through the package manager, enabling Cardboard XR Plugin in Player Settings > XR Plug-in Management cause the error:

XR Plug-in Management error. Failure reason: Error Message: Unable to add package [com.google.xr.cardboard]

Instead I have forked Google cardboard-xr-plugin you originally install from the git repo and patched the sdk.aar file.

So by the time, Google fixes its own repo, you can add the Unity package from this url instead:

https://github.com/dletozeun/cardboard-xr-plugin.git

Hopefully, you should be able from there to check Cardboard XR Plugin this time.

Thanks dletozeun, this is now working for me In 2020.1.7f1. I did have to increase the minimum supported API under Project Settings->Player->Android->Other Setings->Minimum API Level (I chose Android 6/API level 23), and I was able to compile and run the project on an Android 8.1.

jballoffet commented 4 years ago

A fix for this has been submitted and it will be included in the next release (to be released very soon, currently working through the QA process). Thank you for your patience.

chaosemer commented 4 years ago

This was fixed in v1.3.0.