stride3d/stride · error · Exception

OculusOvr.GetError()

Error message

OculusOvr.GetError()

What it means

OculusOvrHmd.Enable calls OculusOvr.CreateTexturesDx to build the eye-buffer swapchain (and optional mirror texture) on the app's D3D11 device. When the native call returns false, the wrapper throws an Exception containing the last LibOVR error string, since swapchain creation is mandatory for rendering to the headset.

Solutions

  1. Read the LibOVR error string in the exception to identify the native failure cause.
  2. Ensure the headset is connected and the Oculus runtime is running before calling Enable.
  3. Verify RenderFrameScaling is a sane value (e.g. 1.0) and mirror width/height are valid when requireMirror is true.
  4. Recreate the session (CreateSessionDx) if the previous session was invalidated, then retry Enable.
Defensive patterns

Strategy: try-catch

Validate before calling

// C#
bool canEnable = OculusRuntime.IsRunning && hmd.IsConnected && GraphicsDevice.GraphicsBackend == GraphicsBackend.Direct3D11;

Try / catch

// C#
try { hmd.Enable(); }
catch (Exception ex) { Logger.Warning("Oculus HMD enable failed: " + ex.Message); vrAvailable = false; }

Prevention

When it happens

Trigger: Enabling the HMD when CreateTexturesDx fails: no valid ovrSession, incompatible D3D11 device or adapter, invalid RenderFrameScaling, or mirror dimensions requested (requireMirror) that the runtime rejects.

Common situations: Headset disconnected or Oculus runtime not running; requesting a mirror window with zero/invalid dimensions; GPU driver issues or device removed during Enable; calling Enable before CreateSessionDx succeeded.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/118e203202cb8904. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.VirtualReality/OculusOVR/OculusOvrHmd.cs:61

            }

            if (ovrSession != IntPtr.Zero)
            {
                OculusOvr.DestroySession(ovrSession);
                ovrSession = IntPtr.Zero;
            }
        }

        public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager graphicsDeviceManager, bool requireMirror, int mirrorWidth, int mirrorHeight)
        {
            graphicsDevice = device;
            long adapterId;
            ovrSession = OculusOvr.CreateSessionDx(out adapterId);
            //Game.GraphicsDeviceManager.RequiredAdapterUid = adapterId.ToString(); //should not be needed

            if (!OculusOvr.CreateTexturesDx(ovrSession, (nint) device.NativeDevice.Handle, out var texturesCount, RenderFrameScaling, requireMirror ? mirrorWidth : 0, requireMirror ? mirrorHeight : 0))
            {
                throw new Exception(OculusOvr.GetError());
            }

            if (requireMirror)
            {
                var mirrorTex = (ID3D11Texture2D*) OculusOvr.GetMirrorTexture(ovrSession, Dx11Texture2DGuid);

                MirrorTexture = new Texture(device).InitializeFromImpl(mirrorTex, treatAsSrgb: false);

                // We don't need to take ownership of the COM pointer.
                //   We are already AddRef()ing in Texture.InitializeFromImpl when storing the COM pointer;
                //   compensate with Release() to return the reference count to its previous value
                mirrorTex->Release();
            }

            textures = new Texture[texturesCount];
            for (var i = 0; i < texturesCount; i++)
            {
                var ptr = OculusOvr.GetTextureDx(ovrSession, Dx11Texture2DGuid, i);

View on GitHub (pinned to 96fad776d2)