Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMD crashes when loading a new scene #127

Closed
demonixis opened this issue Feb 19, 2016 · 29 comments
Closed

HMD crashes when loading a new scene #127

demonixis opened this issue Feb 19, 2016 · 29 comments

Comments

@demonixis
Copy link
Contributor

Hi,

I encounter a serious issue with my project. First there is my setup

  • GTX 750
  • Core 5i
  • Windows 10 x64
  • Latest Core
  • Latest Unity SDK
  • Direct Mode

I've many scenes in my game, if I start the game, all works great but when I change the active scene using SceneManager, my HMD crashes, sometime Windows can't detect it and I've to unplug/plug the HDM many time to have it working again. Sometime when I change the active scene, the image in the HMD is not cleared and no more updated, however, the image on the PC screen is updated.

To support OSVR in my game I've a gameObject in the root scene called ClientKit. This GO contains two scripts, ClientKit which is enabled and a custom script, OSVRManager, which is used to add DisplayController to the parent's node of main camera and VRViewer to the main camera. In fact this is my script :

using OSVR.Unity;
using UnityEngine;

namespace Demonixis.Toolbox.VR
{
    public sealed class OSVRManager : MonoBehaviour
    {
        [SerializeField]
        private ClientKit _clientKit = null;

        public ClientKit ClientKit
        {
            get { return _clientKit; }
        }

#if !UNITY_STANDALONE
        void Awake()
        {
            DestroyImmediate(gameObject);
        }

        void OnEnabled()
        {
            DestroyImmediate(gameObject);
        }
#endif

        void Start()
        {
#if UNITY_STANDALONE
            if (GameVRSettings.HasOSVRHMDEnabled())
            {
                var camera = Camera.main;
                if (camera != null)
                {
                    _clientKit.enabled = true;
                    camera.transform.parent.gameObject.AddComponent(typeof(DisplayController));
                    camera.gameObject.AddComponent(typeof(VRViewer));
                }
            }
            else
                _clientKit.enabled = false;
#endif
        }
    }
}

I don't know why it's crashing.. I hope that you can help me guys.

demonixis.

@DuFF14
Copy link
Member

DuFF14 commented Feb 19, 2016

Hi,
I'm not sure if its related to anything in your script, since I've seen a similar issue here OSVR/Unity-VR-Samples#4, where it crashes in the editor but not builds. I'll reinvestigate but I seem to remember not being able to reproduce it in every project/scene, but couldnt figure out why.

Does it only crash in the editor, or builds as well?
Do you see any error messages in the logs?

@demonixis
Copy link
Contributor Author

output_log.txt

2016-02-19_191102.zip

Hi,

I've this problem in the editor AND in the final builds. I have took a look at the ClientKit.cs file. It seems that the context is disposed when a scene is unloaded.

https://github.com/OSVR/OSVR-Unity/blob/master/OSVR-Unity/Assets/OSVRUnity/src/ClientKit.cs#L145

The Stop method is called by OnApplicationQuit, OnDestroy and OnDisable.

ClientKit uses the DontDestroyOnLoad function to prevent the gameobject to be removed, so the OnApplicationQuit and OnDestroy are NOT called when a scene is loaded.
However, the OnDisable method must be called and it calls the Stop method which will destroy the context object.

I can't test that right now, but I'll investigate this after work.

Edit: I encounter the issue OSVR/OSVR-HDK-Windows-Drivers#4 when the HMD crashes.

Edit 2: I have almost solved the problem. This is my OSVRManager now

void Awake()
{
    StartCoroutine(CheckSupport());
}

void OnLevelWasLoaded(int level)
{
    StartCoroutine(CheckSupport());
}

private System.Collections.IEnumerator CheckSupport()
{
    yield return new WaitForEndOfFrame();

    if (GameVRSettings.HasOSVRHMDEnabled(true))
    {
        var camera = Camera.main;
        if (camera != null)
        {
            if (!_clientKit.enabled)
                _clientKit.enabled = true;

            camera.transform.parent.gameObject.AddComponent(typeof(DisplayController));
            camera.gameObject.AddComponent(typeof(VRViewer));
        }
    }
    else
        _clientKit.enabled = false;
}

Now when I switch to a Level, I've this error Releasing render texture that is set to be RenderTexture.active!

Edit3: Added a zip file with debug output following a crash of a build.

2016-02-19_191102.zip

@demonixis
Copy link
Contributor Author

Well I've some news for you guys.

I tried a lot of different scenarios and that's what I have founded.

In my game, I was using a manager to add the DisplayController and VRViewer components to my player. It appears that attaching these scripts on runtime cause an instant crash when I start the game. Oh and the ClientKit prefab was present on ALL my scenes.

So I tried something else.. I have attached these scripts to my player directly (it's not very good for now because it spams a lot the console if ClientKit is not here...) and just used ONE clientKit prefab (on the very first scene).

The second solution is better, however I still have the Releasing render texture that is set to be RenderTexture.active!. The builds are working (SBS for x86 and Direct Mode for x64) BUT when a scene is loaded, the driver crashes after some seconds. I reported a bug right here OSVR/OSVR-HDK-Windows-Drivers#4.

This is a use case

First test

  1. I start the game, the Splashscreen scene is loaded, the first instance of clientkit is executed, the game works in VR. After few seconds, another scene is loaded.
  2. The menu is loaded, all seems to works as expected, I can use the head tracking. I choose to create a new game. The LoaderScreen scene is loaded.
  3. The loader screen is loaded, it takes too much time to see anything strange... So the game level is loaded.
  4. I'm on the level, I can move, use my head to look everywhere, it's awesome. After some seconds, it varies, I loose the head tracking function, but I still have the rendering. I can move the player but no head tracking. After few seconds, the display on the HDM is no more updated, it seems to be freezed. My driver crashes and Windows says that a USB device is not well detected.
  5. I can't do anything
  6. In fact I have to unplug the Beltbox and all cables, wait a bit, replug them. Power, then USB and finally the HDMI. I restart the server.
  7. I regained the Headtracking and the display into the HMD!

Second test case

  1. I'm in the Unity Editor
  2. I start a level and before that, I've added to scene a prefab ClientKit (because in the full game, the prefab is just in the splashscreen scene).
  3. I can't play, no crashes, all is OK
  4. I decide to go to the menu
  5. The menu is loaded, it's cool all works good
  6. But when I load another scene I have a driver crash.

This is the output of the server

errorosvr

What do you think guys?

@DuFF14
Copy link
Member

DuFF14 commented Feb 22, 2016

Thanks for the details. This may be an issue with the firmware. I'll update this thread as soon as we're able to test a firmware update (this week hopefully).

@demonixis
Copy link
Contributor Author

@DuFF14 I updated the firmware of the HDK this morning, have you a changelog?

@DuFF14
Copy link
Member

DuFF14 commented Mar 5, 2016

No changes in the Unity repo, just updated RenderManager dlls. I have yet to try with the latest firmware.

@DuFF14
Copy link
Member

DuFF14 commented Mar 7, 2016

Looks like this is still an issue after 1.89 firmware upgrade.

@demonixis
Copy link
Contributor Author

I can confirm that it's not yet fixed, however I think we can prevent that in the code by detecting the issue. I'm working on a refacto/fix branch, I hope it'll works ;)

@DuFF14
Copy link
Member

DuFF14 commented Mar 7, 2016

Note this occurs for me whether DirectMode is enabled or not, or when Rendermanager is used or not. Has anyone else seen these error after the USB connection drops?

(Filename: Assets/OSVRUnity/src/ClientKit.cs Line: 155)

ObjectDisposedException: The object was used after being disposed.
  at System.Runtime.InteropServices.SafeHandle.DangerousAddRef (System.Boolean& success) [0x0000c] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.InteropServices/SafeHandle.cs:111 
  at (wrapper managed-to-native) OSVR.ClientKit.DisplayConfigNative:osvrClientCheckDisplayStartup (OSVR.ClientKit.SafeDisplayConfigHandle)
  at OSVR.ClientKit.DisplayConfig.CheckDisplayStartup () [0x00000] in z:\j\workspace\Managed-OSVR\ClientKit\Display.cs:241 
  at OSVR.Unity.DisplayController.CheckDisplayStartup () [0x00000] in C:\Users\Greg\Documents\OSVR\Unity-VR-Samples\Assets\OSVRUnity\src\DisplayController.cs:328 
  at OSVR.Unity.VRViewer.OnPreCull () [0x00000] in C:\Users\Greg\Documents\OSVR\Unity-VR-Samples\Assets\OSVRUnity\src\VRViewer.cs:229 
UnityEditor.EditorGUIUtility:INTERNAL_CALL_RenderGameViewCamerasInternal(Rect&, Int32, Boolean, Boolean)
UnityEditor.EditorGUIUtility:RenderGameViewCamerasInternal(Rect, Int32, Boolean, Boolean) (at C:\buildslave\unity\build\artifacts\generated\common\editor\EditorGUIUtilityBindings.gen.cs:597)
UnityEditor.GameView:OnGUI() (at C:\buildslave\unity\build\Editor\Mono\GameView\GameView.cs:425)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
System.Reflection.MethodBase:Invoke(Object, Object[]) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView:Invoke(String, Object) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:187)
UnityEditor.HostView:Invoke(String) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:180)
UnityEditor.DockArea:OnGUI() (at C:\buildslave\unity\build\Editor\Mono\GUI\DockArea.cs:336)

(Filename: /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.InteropServices/SafeHandle.cs Line: 111)

ObjectDisposedException: The object was used after being disposed.
  at System.Runtime.InteropServices.SafeHandle.DangerousAddRef (System.Boolean& success) [0x0000c] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.InteropServices/SafeHandle.cs:111 
  at (wrapper managed-to-native) OSVR.ClientKit.DisplayConfigNative:osvrClientCheckDisplayStartup (OSVR.ClientKit.SafeDisplayConfigHandle)
  at OSVR.ClientKit.DisplayConfig.CheckDisplayStartup () [0x00000] in z:\j\workspace\Managed-OSVR\ClientKit\Display.cs:241 
  at OSVR.Unity.DisplayController.CheckDisplayStartup () [0x00000] in C:\Users\Greg\Documents\OSVR\Unity-VR-Samples\Assets\OSVRUnity\src\DisplayController.cs:328 
  at OSVR.Unity.VRViewer+<EndOfFrame>c__Iterator1.MoveNext () [0x00038] in C:\Users\Greg\Documents\OSVR\Unity-VR-Samples\Assets\OSVRUnity\src\VRViewer.cs:277 
UnityEditor.EditorGUIUtility:INTERNAL_CALL_RenderGameViewCamerasInternal(Rect&, Int32, Boolean, Boolean)
UnityEditor.EditorGUIUtility:RenderGameViewCamerasInternal(Rect, Int32, Boolean, Boolean) (at C:\buildslave\unity\build\artifacts\generated\common\editor\EditorGUIUtilityBindings.gen.cs:597)
UnityEditor.GameView:OnGUI() (at C:\buildslave\unity\build\Editor\Mono\GameView\GameView.cs:425)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
System.Reflection.MethodBase:Invoke(Object, Object[]) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView:Invoke(String, Object) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:187)
UnityEditor.HostView:Invoke(String) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:180)
UnityEditor.DockArea:OnGUI() (at C:\buildslave\unity\build\Editor\Mono\GUI\DockArea.cs:336)

@DuFF14
Copy link
Member

DuFF14 commented Mar 22, 2016

To update, the issue I was seeing were fixed by #138, but I think @demonixis is still having problems in the editor, but not in builds.

@demonixis
Copy link
Contributor Author

@DuFF14 Yes I confirm that I already have random crashes with Unity, both Editor and Builds... I don't know why but I noticed one thing : I use post processes and I don't see them in the HDK (Direct Mode), do you think it can be related to that issue?

@chase-cobb
Copy link

@DuFF14 - It seems like the original issue was fixed. Can this issue be closed and open a new ticket for the other issue? If it wasn't fixed, I'm not sure what the actual issue is. Maybe splitting this into multiple tickets is the correct path?

@demonixis - Could you open a new ticket with more information on your current issue?

@demonixis
Copy link
Contributor Author

@chase-cobb Please do not close this issue because all errors are the same, the only difference is that I have updated the firmware of my HDK since I opened it. What do you want when you ast "More information" ?

@chase-cobb
Copy link

@demonixis I'm not suggesting we don't fix you up, but rather isolate the multiple issues discussed in this thread. This is to disambiguate, streamline discussion, and prevent this thread from being a catch-all for all bugs related to start-up and scene swapping. :)

There was in fact a bug in the main code path and samples that prevented swapping scenes. This issue was fixed here -> PR #138

Your current issue seems to be more related to usage outside of the expected workflow and could be triggering another post processing issue? It would be nice to have dedicated threads and the smallest repro example project you could create.

@JacExec
Copy link

JacExec commented Apr 14, 2016

Same scene loading issue

My config;
GeForce GTX 780
Intel(R) Core(TM) i7-4770K
24.00 GB RAM
Driver Nvidia 362.00
Windows 8.1

OSVR- Unity version 0.6.8.0 with core 0.6.1176-gba5951
OSVR Runtime for Windows 0.6.1176-g9ba5951
OSVR-HDK windows driver 1.2.6
Updated firmware

Any news?

@DuFF14
Copy link
Member

DuFF14 commented Apr 19, 2016

I've tested projects from @JacBellu and @demonixis, but so far haven't been able to reproduce this issue on either of my machines (GTX 960, Win 8.1 / GTX 980, Win 8.1, 364.72 Nvidia drivers). Tested on HDK 1.2, 1.3, and DK2.

@JacExec
Copy link

JacExec commented Apr 19, 2016

Thank you @DuFF14 for your support. What about using Nvidia drivers 364.72 instead of 362.00 as you suggested? Anyway.. I will try my project on different config

@DuFF14
Copy link
Member

DuFF14 commented Apr 19, 2016

I updated to 364.72 after this merge, which seems to have fixed that issue for me. sensics/OSVR-RenderManager#70

It looks like your renderManager dll was dated from the day before, so perhaps something else was going on.

Not sure if we're out of the woods yet with that issue, but perhaps others can confirm that 364.72 drivers are now working with the latest RM build (included in OSVRUnity plugin).

@demonixis
Copy link
Contributor Author

demonixis commented Apr 20, 2016 via email

@DuFF14
Copy link
Member

DuFF14 commented Apr 20, 2016

@demonixis @JacBellu there is a new PR open that addresses an issue on some systems where Unity was causing OSVR server to hang at startup (#154). Could one of you test this to see if it also fixes the scene switching bug? Only one file has changed, OsvrRenderManager.cs, so it might be easiest to just copy/paste the new file in your existing project.
Here is the new file: https://github.com/OSVR/OSVR-Unity/blob/renderManager_client_context/OSVR-Unity/Assets/OSVRUnity/src/OsvrRenderManager.cs

@demonixis
Copy link
Contributor Author

Hi,

I have made new tests with the latest core + Unity SDK (pulled yesterday) and I have once again the issue. That's appears on another project so I'm a bit confused. I have used the HDK last week at my job for 5 days and I have encoutered some crashes of the server but I never loose the USB driver.

So it's on my PC only and that's very strange.. My configuration

  • GeForce 750 GTX
  • Core i5-3350P @ 3.1 Ghz
  • Windows 10 x64 Pro stable / updated
  • Nvidia 364.72 (same issue with older drivers)
  • Unity 5.3.4p3

@JacExec
Copy link

JacExec commented Apr 24, 2016

Hi,
I also made some tests on two different configuration with no encouraging results, same issue like described by @demonixis, I do not understand what is going on.

screenshot 292348

@DuFF14
Copy link
Member

DuFF14 commented Apr 25, 2016

@JacBellu @demonixis is the issue still present if RenderManager extended mode is used rather than DirectMode?

How about if RenderManager isn't used at all?

Config file with extended mode:

{
"display": "displays/OSVR_HDK_1_3.json",
"renderManagerConfig": "sample-configs/renderManager.extended.landscape.json"
}

Config file with no RenderManager:

{
"display": "displays/OSVR_HDK_1_3.json"
}

@JacExec
Copy link

JacExec commented Apr 26, 2016

I'm testing in extended mode with RenderManager while manteining the window onto my main monitor and everything works (no crash anymore). However now there is no distortion correction.

(HDK 2nd display setted in Portrait mode in 1080 * 1920)

@JacExec
Copy link

JacExec commented May 3, 2016

Is there some news about this issue?
We could not improve the situation since last support contact.

@demonixis
Copy link
Contributor Author

I'm working on a single scene game so I havn't this issue. However the server crashes after many play/stop use... But that's another bug.

@DuFF14
Copy link
Member

DuFF14 commented May 24, 2016

@JacBellu Getting back to chasing this one. I also find no crashes when using RenderManager in extended mode, but it definitely should still have distortion correction. That doesn't change whether you're in direct mode or not, so double check your distortion in the config file.

@DuFF14
Copy link
Member

DuFF14 commented May 25, 2016

Hopefully this PR fixes it #163

@DuFF14
Copy link
Member

DuFF14 commented Aug 17, 2016

Haven't encountered this or heard any reports of crashing since #163, closing this issue.

@DuFF14 DuFF14 closed this as completed Aug 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants