{"record":{"id":"118e203202cb8904","repo":"stride3d/stride","slug":"oculusovr-geterror-oculusovrhmd","errorCode":null,"errorMessage":"OculusOvr.GetError()","messagePattern":"OculusOvr\\.GetError\\(\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.VirtualReality/OculusOVR/OculusOvrHmd.cs","lineNumber":61,"sourceCode":"            }\n\n            if (ovrSession != IntPtr.Zero)\n            {\n                OculusOvr.DestroySession(ovrSession);\n                ovrSession = IntPtr.Zero;\n            }\n        }\n\n        public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager graphicsDeviceManager, bool requireMirror, int mirrorWidth, int mirrorHeight)\n        {\n            graphicsDevice = device;\n            long adapterId;\n            ovrSession = OculusOvr.CreateSessionDx(out adapterId);\n            //Game.GraphicsDeviceManager.RequiredAdapterUid = adapterId.ToString(); //should not be needed\n\n            if (!OculusOvr.CreateTexturesDx(ovrSession, (nint) device.NativeDevice.Handle, out var texturesCount, RenderFrameScaling, requireMirror ? mirrorWidth : 0, requireMirror ? mirrorHeight : 0))\n            {\n                throw new Exception(OculusOvr.GetError());\n            }\n\n            if (requireMirror)\n            {\n                var mirrorTex = (ID3D11Texture2D*) OculusOvr.GetMirrorTexture(ovrSession, Dx11Texture2DGuid);\n\n                MirrorTexture = new Texture(device).InitializeFromImpl(mirrorTex, treatAsSrgb: false);\n\n                // We don't need to take ownership of the COM pointer.\n                //   We are already AddRef()ing in Texture.InitializeFromImpl when storing the COM pointer;\n                //   compensate with Release() to return the reference count to its previous value\n                mirrorTex->Release();\n            }\n\n            textures = new Texture[texturesCount];\n            for (var i = 0; i < texturesCount; i++)\n            {\n                var ptr = OculusOvr.GetTextureDx(ovrSession, Dx11Texture2DGuid, i);","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.VirtualReality/OculusOVR/OculusOvrHmd.cs#L43-L79","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the LibOVR error string in the exception to identify the native failure cause.","Ensure the headset is connected and the Oculus runtime is running before calling Enable.","Verify RenderFrameScaling is a sane value (e.g. 1.0) and mirror width/height are valid when requireMirror is true.","Recreate the session (CreateSessionDx) if the previous session was invalidated, then retry Enable."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// C#\nbool canEnable = OculusRuntime.IsRunning && hmd.IsConnected && GraphicsDevice.GraphicsBackend == GraphicsBackend.Direct3D11;","typeGuard":null,"tryCatchPattern":"// C#\ntry { hmd.Enable(); }\ncatch (Exception ex) { Logger.Warning(\"Oculus HMD enable failed: \" + ex.Message); vrAvailable = false; }","preventionTips":["Verify headset connection and Oculus runtime status before Enable","Keep RenderFrameScaling at sane values (around 1.0)","Pass valid mirror dimensions whenever requireMirror is true","Catch Enable failures to degrade gracefully to flat rendering"],"tags":["vr","oculus","native-interop","initialization"],"backgroundTag":"module-init-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}