Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

VRSettings.LoadDeviceByName("None") closes the Editor / Player. Same with OpenVR.Shutdown.

Discussion in '5.4 Beta' started by shawnblais, Jul 21, 2016.

  1. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    I'm building a multiplayer VR game and trying to run 2 instances of the client on the same machine for more rapid development.

    Each time I launch one of the clients, it shuts down the other (which I guess is expected behavior for a VR app) but in our case we want the first client to keep running, with no VR, switching over to an automated bot-mode, so the VR tester can play against a remote AI of sorts, fully testing the netcode, without needing a 2nd VIVE or tester.

    Disabling VR should be no problem, but I can't find a way to do it that doesn't also close the app :(

    * VRSettings.enabled stops VR from rendering, but it does not stop the application from being shutdown when a 2nd instance is launched.
    * VRSettings.LoadDeviceByName("None") closes the application (including UnityEditor in Play Mode!)
    * OpenVR.Shutdown() closes the application (including UnityEditor in Play Mode)
     
  2. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    FWIW, I also tried it in the reverse. I set NONE as the initial option, and then loaded in OpenVR only in the 2nd instance. Nothing crashed in this case, OpenVR said it initialized ok, but the headset just showed the default loading area, and no input from Unity was received.

    This might be two seperate bugs...in this case:
    1. Set None as initial option
    2. Call VRSettings.LoadDeviceByName("OpenVR")
    3. Observe console log: "OpenVR initialized!"
    4. Observe as your VIVE headset receives no input from Unity.
     
    Last edited: Jul 21, 2016
  3. Alex-Lian

    Alex-Lian

    Guest

    Asking the VR team to take a look. Regarding OpenVR.Shutdown, I suspect you'll need to take that back to Valve.
     
  4. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    398
    These are valid use cases. We'll take a look.
     
  5. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Thanks guys. This would be allow a huge production boost for us. My hunch is that calling VRSettings.LoadDeviceByName("None"), calls OpenVR.ShutDown() under the hood, causing the app to be shut down, so maybe it's all the same issue.

    Ideally just setting VRSettings.enabled=false would be enough to sever the connect to OpenVR without shutting down. We can always call Application.Quit ourselves, and typically Steam manages app lifecycle anyways.
     
  6. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    I have a repro project I created locally that simply calls LoadDeviceByName("none") when I press k. Running it standalone with my Vive headset I can exit OpenVR and go in to None with no issues. I can then hit play in the editor and the editor works fine tracking the HMD.

    Can you upload a minimal repro example for use to look at?
     
  7. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Also, not sure if that made any difference, but Steam updated my Firmware and app today. Not sure when exactly that really happened since the last time I plugged the gear was a couple weeks ago.
     
  8. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Thanks Joejo, will do, are you using f2 or f1? f1 was the latest last night when I was testing this.
     
  9. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  10. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Alright, so the crash seems to be linked to the presense of the SteamVr [CameraRig] prefab.

    If that prefab was active in the scene (at any point), and you load Device "None" the crash will occur.

    If you're using just a normal camera, and load NONE, all is good. Here's a reproduction case, but all you need to do on your end is drop SteamVR>[CameraRig] into the scene, and re-run your test. It should crash.

    I did find one workaround which is, if I have a script, and set it's Script Execution Order < Default, and I disable the [CameraRig] in Awake(), then it does not seem to get initialized, and the shut down will not occur. Not ideal, but I can work with this approach for now :)



    [Edit] After digging into it some more, I've isolated it to this single line which causes this behavior:

    SteamVR_Camera.OnEnable(){
    SteamVR_Render.Add(this); //Comment this out to prevent shutdown
    }

    Can't really figure out why tho....
     
    Last edited: Jul 21, 2016
  11. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    (Not sure what happened to my reply post yesterday...)

    The problem is that the SteamVR plugin is assuming that once you are in OpenVR mode you are always in OpenVR mode and so the pointer the the native plugin instance that they cache, once set, is always available. In your case, though, you are causing Unity to tear down the VR instance leaving the SteamVR plugin with a dangling pointer in their SteamVR.instance property. This then causes a crash in the SteamVR_Render.OnUpdate callback when they go to call GetFrameTimer off the vr instance.

    The quick fix is for you to add the following to the top of the OnUpdate callback in SteamVR_Render:

    if (!VRSettings.enabled)
    {
    return;
    }

    And that should take care of the problem you are having.

    I've reported this to Valve so hopefully they will get an update out to the Asset on the Asset Store at some point.
     
    Ostwind likes this.
  12. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Wicked, thanks for the attention guys really appreciate the quick responses. And thanks for passing on to Valve, wasn't sure how to really go about that.
     
  13. aleiby

    aleiby

    Joined:
    Mar 14, 2012
    Posts:
    13
    As a more general solution (and one I'll include in the next update) you can modify SteamVR.enabled to the following:

    public static bool enabled
    {

    get
    {
    #if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
    if (!UnityEngine.VR.VRSettings.enabled)
    enabled = false;
    #endif
    return _enabled;
    }
    set
    {

    _enabled = value;
    if (!_enabled)

    SafeDispose();
    }
    }
     
    Last edited: Jul 22, 2016