ValveSoftware / unity-xr-plugin

OpenVR plugin for Unity's XR API
BSD 3-Clause "New" or "Revised" License
309 stars 64 forks source link

Fallback camera does not render to desktop window #41

Closed scolarod closed 3 years ago

scolarod commented 4 years ago

When running Unity game with no HMD, the fallback camera does not render to the main display. I have tested this in my game and the interactions sample in both the editor and standalone build. When selecting the fallback camera in the editor, the camera preview and the WASD key movement look correct.

Unity 2020.1.3f1 (standard render pipeline) OpenVR XR Plugin 1.0.1 SteamVR Plugin 2.6.1 (also tried 2.6.0.b4)

I realize this is probably a low priority but the 2D fallback view is extremely useful for demoing to clients that may not have access to a HMD.

joejo-unity commented 3 years ago

There are 2 problems here:

  1. XR Plug-in Management expect Initialize to succeed or fail and then uses that to fallback. Success in init means management assumes Start will succeed and we don't fallback to anything else after that. You can find relevant information on that here.
  2. If anything fails after creating any subsystems, then the created subsystems should be destroyed. In the case of OpenVR that seem to be a must otherwise the screen stays black.

Here is a diff that should resolve this (sorry for formatting, github didn't like the paste):


index 4ed79eb..943f753 100644
--- a/com.valve.openvr/Runtime/OpenVRLoader.cs
+++ b/com.valve.openvr/Runtime/OpenVRLoader.cs
@@ -185,6 +185,14 @@ namespace Unity.XR.OpenVR
 #endif

             CreateSubsystem<XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "OpenVR Display");

+            EVRInitError result = GetInitializationResult();
+            if (result != EVRInitError.None)
+            {
+                DestroySubsystem<XRDisplaySubsystem>();
+                Debug.LogError("<b>[OpenVR]</b> Could not initialize OpenVR. Error code: " + result.ToString());
+                return false;
+            }
+
             CreateSubsystem<XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "OpenVR Input");

             OpenVREvents.Initialize();

@@ -223,13 +230,7 @@ namespace Unity.XR.OpenVR
             StartSubsystem<XRDisplaySubsystem>();
             StartSubsystem<XRInputSubsystem>();

-            EVRInitError result = GetInitializationResult();

-            if (result != EVRInitError.None)
-            {
-                Debug.LogError("<b>[OpenVR]</b> Could not initialize OpenVR. Error code: " + result.ToString());
-                return false;
-            }

 #if !UNITY_METRO
             try```
1runeberg commented 3 years ago

Thanks @joejo-unity !

Currently internally testing. But pushed in this branch, the updated latest headers you provided (xx19.4) and fix for this here: https://github.com/ValveSoftware/unity-xr-plugin/tree/dev/UpdatedHeaders

joejo-unity commented 3 years ago

Awesome!!

On Fri, Sep 18, 2020 at 5:17 PM Rune Berg notifications@github.com wrote:

Thanks @joejo-unity https://github.com/joejo-unity !

Currently internally testing. But pushed in this branch, the updated latest headers you provided (xx19.4) and fix for this here:

https://github.com/ValveSoftware/unity-xr-plugin/tree/dev/UpdatedHeaders

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ValveSoftware/unity-xr-plugin/issues/41#issuecomment-695135515, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFQI6O5YE34AF3E644AXQEDSGP2CBANCNFSM4QR6ULRQ .

-- Joseph Jones Senior Software Engineer Unity3D

zite commented 3 years ago

Hi, thanks for reporting the issue. This should be fixed in the latest release. You're welcome to give it a try and let us know if it solves the problem. https://github.com/ValveSoftware/unity-xr-plugin/releases/tag/v1.1.1b

kisak-valve commented 3 years ago

Closing per the last comment.