Gvr-unity-sdk: Cardboard (and hybrid 2D+Daydream) apps crash on S8 when screen resolution is not WQHD+ (Switching Between VR.enabled cause crash)

Created on 31 Jul 2017  Â·  67Comments  Â·  Source: googlevr/gvr-unity-sdk

Hi, everyone

I had issue with switching between 2D and VR Mode
This method cause crash

StartCoroutine(LoadDevice("cardboard"));

IEnumerator LoadDevice(string newDevice)
{
    yield return null;
    VRSettings.LoadDeviceByName(newDevice);
    yield return null;
    VRSettings.enabled = true;
}

`
LOGCAT
libEGL : eglCreateWindowSurface: native_window_api_connect (win=0xc687d808) failed (0xffffffed) (already connected to another API?)
libEGL : eglCreateWindowSurface:484 error 3003 (EGL_BAD_ALLOC)
Unity : [EGL] Failed to create window surface: EGL_BAD_ALLOC: EGL failed to allocate resources for the requested operation.
Unity :
Unity : (Filename: ./Runtime/GfxDevice/egl/WindowContextEGL.cpp Line: 141)
Unity :
libEGL : call to OpenGL ES API with no current context (logged once per thread)

Im using Unity 5.6.0f3 and Samsung S8

I see many similar problem with this method but anyone find solution?

bug

Most helpful comment

No definitive ETA, but we're actively exploring several solutions together with Samsung. We'll keep this thread posted as we have more concrete details to share.

All 67 comments

Update, On Unity 2017.1.0f3 same issue

Update, On my old Fly IQ4516 everething works fine.
I think this crash happens on Samsung S8 after android update, which I got few days ago, after this update I didnt test VR mode in my app.

Hi VadimTikhonyuk, can you attach a full log for this crash?

I have the same use case and what appears to be the same problem.

Phone: Samsung Galaxy S8 Plus
Unity version: 2017.1.0f3
Code that I am using to crash the game:

    public void initiatevr()
    {
        StartCoroutine(initiatevrcoroutine());
    }

    IEnumerator initiatevrcoroutine()
    {
        Debug.Log("Initiating the VR Sequence");
        VRSettings.LoadDeviceByName("Cardboard");
        yield return null;
        VRSettings.enabled = true;
        Debug.Log("VR Sequence initiation complete");
    }

I put Debug.log strings in the code so you can see it in the logcat output more easily.

Some things of note:
The game does not crash if you disable Google VR Services. This is replicated with the version that shipped with the phone, as well as the latest version which as of this moment is 1.7.161000338

The game does not crash on my old handset which is an LG G2.

Building with a mono back end or using IL2CPP makes no difference. Crash is the same.

I attached the logcat for the crash so you can check it out.

bestiLogcat.txt

Hi, tedruxpin,
There is log file, I cut it from adb logcat, so something important maybe lost, because full logfile is huge
log.txt

On S8+, can you let us know if the Cardboard app runs correctly (no crash) when you set the phone's screen resolution to the native device resolution:

Settings > Display > Screen resolution > WQHD+ > _APPLY_

I have the same problem with a S8.

@fredsa : I made the test you asked for. Here's the results, with the latest Google VR Services update :

  • S8 with the Google VR Services activated, @FHD+(2220x1080) resolution = crash on startup for the app
  • S8 with the Google VR Services deactivated @FHD+(2220x1080) resolution = app runs fine, I can push screen luminosity as high as I want
  • S8 with the Google VR Services deactivated @FHD+(2220x1080) resolution = app runs fine, I can push screen luminosity as high as I want, _it doesn't crash if I switch back to the panel, activate Google VR Services while the app is running and go back to the app_
  • S8 with the Google VR Services activated @WQHD+(2960x1440) resolution = app runs fine, _I can't push screen luminosity as high as I want, and it seems that the phones goes in low persistence mode._
  • S8 with the Google VR Services deactivated @WQHD+(2960x1440) resolution = app runs fine, _I can push screen luminosity as high as I want, and the phone doesn't goes into low persistence mode_ (I suppose it's because the Service isn't activated).

@fredsa There have any way to open native settings and give user to change resolution. Similar to how this work in Gear VR. I have some skills in writing plugins on java

@Pseudopode, thank you for confirming and sharing your results with WQHD+ and FHD+.

The behavior you're seeing when deactivating Google VR Services is expected as this service is responsible for entering VR mode, which includes enabling Low Persistence mode, which helps greatly with user comfort and image quality.

@VadimTikhonyuk We're looking into this underlying issue. If in the mean time you have a workaround, please feel free to share here.

Hi, is there any progress? We are having the same issue, instant crash on S8/S8+ when using non-native resolution. It would be really wonderful to get a fix asap.

Or is there a way to force user or Android to always switch to native resolution before staring an app?
Thx.

One possible workaround is to add android:configChanges="density" to your Activity's manifest entry. I haven't tried this on Unity, but it works for a similar Android issue on the S8.

Using a test apk, built using Unity 2017.1.0p4, it appears that it's not quite enough to use android:configChanges="density|…" in the app's activity.

Although this does prevent the app from immediately closing when it's launched at a less than full screen resolution, the result is that the stereo output is rendered at the wrong scale.

hd-plus
fhd-plus

We're looking into a couple of potential routes to fix this issue:

  1. An update to the Unity Android Player and the build process, to handle the density change event.
  2. An update to Google VR Services, to avoid the density change in the first place.

Thank you for response.
Just my two cents on the first solution/workaround:

  1. That would require new Unity (patch) release and re-import of ALL projects for every developer. Also from my experience with Unity, it might work in one release and stops working in another...

Could anyone please point me to the root cause of the crash? Is it GVR SDK, GVR service or Unity Player causing this? Thx.

We get the same reports from users with S8+. If it is WQHD it works fine, if not it crashes during switch from 2D to VR. Since the app starts 2D we don't have info on what happens during switch from VR to 2D.

Same on the Samsung Galaxy Note 8, I'm starting in "none" standard mode and loading Cardboard later, at that point crashes out if the device is in FHD+ 2200x1080 mode, change the device to WQHD 2960x1440 and is fine.

Log:

Could not recreate VR window because GfxDevice is in an invalid state (device lost)
[EGL] Attaching window :0xd413b808
onPause
D/VrManagerService: DisableKeycodeWink, component = ComponentInfo{com.conquermobile.ubc.eyetrackpd/com.unity3d.player.UnityPlayerNativeActivity}, enabled = true
V/SystemKeyManager: requestSystemKeyEvent() is called keyCode = 1082 componentName = ComponentInfo{com.conquermobile.ubc.eyetrackpd/com.unity3d.player.UnityPlayerNativeActivity} request = true
ANativeWindow: (2220/1080) RequestedResolution: (0/0) RenderingResolution: (0/0) EGLSurface: (2220/1080)
Error trying to call delegated method pause. null

Just wanted to check up on this issue as I'm getting more and more reports from users of this crash.

This is likely affecting the majority of S8 / S8+ / Note 8 users as those devices ship from the factory at FHD.

I was thinking about pushing out an update to my app that warns these users and prevents VR mode, but since I have the "daydream" VR device as the first in the list (and needs to stay this way for Daydream approval), my app will crash immediately at launch since it loads in VR mode from the beginning.

If anyone has a workaround or insight as to when this might be fixed, I'd very much appreciate it.

It is becoming to be a really pressing issue, especially for developers who have their apps already on Google Play. Bad reviews could bury their apps, nobody cares it's not their fault. I just hope they will be able to fix it via GVR Services update which should be released at the end of this month. If not, then I'll have to do some ugly workarounds.

Also, IMHO, VR (or any app) should keep the resolution user has selected and shouldn't try to switch to native. Software should respect users settings, not override it. This problem shouldn't exist.

We're actively working on a fix for this issue.

In the mean time the best available workaround is to have users change their device's default resolution to WQHD+:

_Settings > Display > Screen resolution > WQHD+ > APPLY_

Thank for the update @fredsa

Do you happen to know if it's going to be a fix to VR services or Unity? Any ETA?

Asking users to switch resolutions isn't really practical as I have no way to reach out to them, and in my case the application crashes immediately at launch so I can't warn them at all.

We're actively working on a fix for this issue.

Is there an ETA of less than a few days or will it be longer?

Just want to know if it is worth working on a "detect and ask S8/S8+/Note8 users" system and pushing it out, or if this fix will come soon.

Just a quick note - I believe this bug will result in all Daydream Unity apps crashing on startup when set to FHD (the default resolution) on S8 / Note 8 devices, at least on the Unity / VR services versions where this bug exists. Please let me know if I can help at all. I'm happy to test any potential fixes or workarounds as this is a bit of a showstopper for me at the moment.

Is there an ETA of less than a few days or will it be longer?

@GavinThornton It will very likely take longer than a few days.

@dustinkerstein This bug covers Cardboard apps. If you're seeing issues with Daydream-only or Daydream/non-VR hybrid apps on S8, it would be great if you could file a separate issues with repro steps there.

@fredsa I was able to directly test a Galaxy S8 via http://developer.samsung.com/remotetestlab and understand the behavior a bit more now. The crash won't happen for most Daydream apps as it appears to only happen when VR mode is toggled (VRSettings.enabled = false <-> true) but it will immediately crash under the exact same conditions as this #671 bug. The only difference is that VR device = "daydream". Should I still create a separate bug?

Also, please see the attached log for the crash - Crash.txt

Effectively, all S8 / Note 8 devices will crash when toggling VR by default due to Samsung setting FHD at the factory.

Thanks @dustinkerstein. Since the root cause appears to be the same, let's track that in this issue. I've updated the issue title to reflect this.

Until this Galaxy S8 / S8+ / Note 8 showstopper is fixed, I'm going to warn these users with this condition: if (SystemInfo.deviceModel.Contains("G950") || SystemInfo.deviceModel.Contains("G955") || SystemInfo.deviceModel.Contains("N950")) but I really would only like to warn users that are set to a resolution other than WQHD+. Has anyone figured out a way in Unity to detect when the device isn't in WQHD+ mode?

It seems like no matter what resolution is set (HD+, FHD+, WQHD+) all of these methods return the values corresponding to WQHD+

  • Screen.dpi
  • Screen.height
  • Screen.width
  • Screen.currentResolution

Are there any other ways to possibly detect this condition?

@dustinkerstein You should be able to get the current resolution by using a full screen canvas and reading canvas width and height in screen space (rotating the device will switch parameters, so you may need to use min and max for determining width and height). Screen class is useless as it always returns native resolution for some reason. If canvas method doesn't work let me know and I'll dig into my projects to find how I solved it before.

Thanks @guneyozsan I will give that a shot.

Also, it's interesting to note that this crash does not happen on the Galaxy S7 / S7 Edge when set to HD, FHD (default in Nougat), or WQHD. The crash is specific to the taller screen (2960 pixels vs. 2560 pixels) of the S8 / Note 8 line of phones.

@guneyozsan I tried both GalaxyWorkaround.transform.localPosition and GalaxyWorkaround.pixelRect.width where GalaxyWorkaround is a Pixel Perfect Screen Space Overlay Canvas and I get the same results for all of the resolutions.

@dustinkerstein I checked and this is how I get the current resolution:

CanvasScaler canvasScaler;
int shortSide = Mathf.Min(Mathf.RoundToInt(canvasScaler.referenceResolution.x), Mathf.RoundToInt(canvasScaler.referenceResolution.y));
int longSide = Mathf.Max(Mathf.RoundToInt(canvasScaler.referenceResolution.x), Mathf.RoundToInt(canvasScaler.referenceResolution.y));

@guneyozsan I wasn't able to get that working as it seems to always return the reference size, not the current scaled size. Would you be able to send over a screenshot of your Canvas and CanvasScaler properties?

@dustinkerstein Ops, you are right. Sorry, it has been a year I did this and the inconsistent results mislead me. Actually Canvas.pixelRect.width/height should also be the solution. Since both Screen class and Canvas.pixelRect.width/height gives native resolution I suspect that Unity always runs in native WQHD and the device downscales the display from WQHD to FHD.

@guneyozsan Yeah, which in turn means that I won't be able to detect this condition and am forced to warn all S8 / S8+ / Note 8 users regardless of their selected resolution :(

There is another interesting bug related to this issue. Calling Screen.SetResolution() in Unity doesn't affect Cardboard's VR viewports at all. They are always being rendered at the initial size (being rendered outside of screen borders for example). What makes this even worse is that calling VRSettings.RenderScale or ViewportRenderScale changes their resolution, but not their on-screen size. So first of all SetResolution() should work correctly, without it nobody can really do any workarounds.

Also, since apps do NOT crash with VR Services turned off, probably because resolution is not being enforced, how hard can it be to release hotfix VRServices version which wouldn't enforce the native res for Cardboard apps?

@OmegaMule Please create a separate issues for the Screen.SetResolution() and VRSettings.renderScale / VRSettings.renderViewportScale issues you're seeing, and link to the Unity bug which will help us track any fixes which need to happen there.

Just wanted to check in to see if there was any ETA for this fix. Happy to help test any beta code or potential workarounds.

No definitive ETA, but we're actively exploring several solutions together with Samsung. We'll keep this thread posted as we have more concrete details to share.

FYI, in case anyone was wondering about the newest Google VR Services update, it doesn't have any effect on this particular issue.

Just wanted to check in. Any news from the Samsung / Unity / GVR side of things?

@dustinkerstein: Unity 2017.1.2p1 "XR: Fixed handling of Android density (screen resolution) changes to avoid a crash."

  • I haven't tried it yet, because I use 5.6.x, but this change should avoid the crash. Whether they also fixed the scaling issue is unknown. Somebody should try it.

A fix for this is also coming to Unity 5.6.x.

@OmegaMule Nice! I just confirmed this is working correctly in 2017.1.2p1 for both FHD+ and WQHD+ resolutions. Toggling VR mode also works correctly.

OK I've tested the crashfix change on Unity 2017.1.2p1 and Unity 5.6.4p1, the result is as I've predicted. Unity devs just added "density" to Android Manifest, which prevents the crash when GVR Services enforce resolution change. The scaling, however, is still not fixed. VR viewports are incorrectly scaled and positioned due to resolution difference.

So this is just first step. Users still need to change resolution to WQHD to use Cardboard.

Is there any ETA for the scaling fix? Thanks.

Update:
Luckily it's possible to create a fully working workaround using Screen.SetResolution() to make it work without user intervention.

@OmegaMule Can you post a screenshot of that? I haven't seen that when testing on the devices here - http://developer.samsung.com/remotetestlab/rtlDeviceList.action

@dustinkerstein:
https://user-images.githubusercontent.com/1235362/30393677-baf78ef4-9875-11e7-971b-f217abded447.png

It looks exactly like that on real Galaxy S8 device and clean Unity version I mentioned before.

Update:
I've also tried it on S8 simulator you posted with the same result.

@OmegaMule Interesting, I am not able to replicate that behavior with my app when testing on the Samsung Remote Device lab (which I believe are in fact real devices, not emulators or simulators). Is it possible to post your project online?

Is there any ETA for the scaling fix? Thanks.

The plan is to push an updated Google VR Services build to resolve the second half of the problem (properly responding to "density" changes when declared in the manifest). We expect the rollout to hit 100% by the end of next week (Nov. 3).

The fix to allow "density" changes without an app restart (by way of the app manifest) has rolled out to 100%. Note that the resolution change will still occur if the user has not explicitly changed the resolution to native.

Separately, we're exploring rollout of a global prompt to change the resolution of the device to native, sometime in December. That will avoid the resolution switch entirely, though it may be suboptimal for some users who don't want their device always running at native resolution.

The fix for this issue requires Unity 5.6.4p1, 2017.1.2p1, and 2017.2.0f3 and VR Services 1.10.172754103 or later.

I can confirm that the combination of Unity 2017.1.2p1 and VR Services 1.10.172754103 is successful. What's the best way to detect if a user doesn't have the latest VR Services installed though?

I ended up using the PackageManager to get the PackageInfo for com.google.vr.vrcore. Then I checked the versionCode to make sure it was at least 160729830 (aka 1.10.172754103). If there's a better way then please let me know. Thanks.

You can also now upgrade to the latest Google VR SDK for Unity (v1.110) which has the Android GVR lib v1.101 embedded in the .unitypackage. This embedded GVR lib has the fix in it and should work even if the user hasn't upgraded their VR Services.

Awesome. That works. Thanks!

Hi, I'm still getting the same problem (crash on start when not in WQHD+) with Samsung S8, Google VR Services 1.10.172754103, Unity 2017.1.2f1, Google VR SDK for Unity (v.1.110)

Other than importing the latest Google VR SDK to my project is there anything else I need to do to make it use the VR lib? Not sure how Unity knows to use the one in the SDK instead of it's own built-in library.

Ok, requires Unity 2017.1.2p1 it seems not working with 2017.1.2f1

When I turn off Google VR Service, my vr app works. But When I turn on Google VR Service in applicatioon ->vr helper etc, my app doesnt work.
If I put vrmode false in AndroidManifest, Google VR Service shouldn't work to my vr app ?
"



"

How can i avoid this problem on s8 and cardboard sdk 0.8?
I tried to build an app in unity 564p2 and unity2017.2.0p2 but I failed.
Is there any solution in cardboard sdk0.8 ?

@hyenachi Version 0.8 of the Google VR SDK for Unity is very old. If you encounter any issues with the latest SDK, please file a new issue for that.

I can not currently upgrade Unity and the SDK on our project but have hit this annoying bug. Can I fix the crash at least with a manifest update like android:configChanges="density" then?

Can I fix the crash at least with a manifest update like android:configChanges="density" then?

You can try, though I don't believe the behavior will be consistent or correct unless you have the latest SDK and Unity version.

Yes I finally could update to latest Unity & I must say it's much better now but what a rocky road to get there from Google!

We're using Unity 2017.3 and gvr-sdk 1.120.0 and there is still the issue with the S8 in the non-WQHD+ resolutions that the output is rendered at the wrong scale.
Fredsa has written about it 4 months ago.

Wrong scale in FHD+

Wrong scale in HD+

Is there any information/workaround/solution available or in prospect?

@jox Can you confirm that the device has the latest version of Google VR Services?

@fredsa
GoogleVR Services is the latest available on my phone. It's version 1.12.177372015 (updated 2017-11-30).

@fredsa By the way, when I go to Settings -> Apps and deactivate the Google VR Services, it will run fine in both non-WQHD+ resolutions. When trying to configure the viewer then, it will ask to install the Cardboard App.

@jox I've been unable to reproduce this using Unity 2017.3.1p1 on a Samsung Galaxy S8.

It would be helpful to know:

  • What's the Android operation system version installed on the device?
    Settings > About phone > Software information > Build number
  • Since there are many SKUs for the S8, what model number are you testing with?
    Settings > About phone > Model number
  • What's the exact version of Unity you're using?
    Unity > About Unity…
  • What's the currently installed Google VR Services version (currently likely 1.13.185188193):
    adb shell pm dump com.google.vr.vrcore | grep version
Was this page helpful?
0 / 5 - 0 ratings