{"record":{"id":"0d74c069c3831ca3","repo":"stride3d/stride","slug":"oculusovr-geterror","errorCode":null,"errorMessage":"OculusOvr.GetError()","messagePattern":"OculusOvr\\.GetError\\(\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.VirtualReality/OculusOVR/OculusOverlay.cs","lineNumber":25,"sourceCode":"using Stride.Graphics;\nusing CommandList = Stride.Graphics.CommandList;\n\nnamespace Stride.VirtualReality\n{\n    internal class OculusOverlay : VROverlay, IDisposable\n    {\n        private readonly IntPtr ovrSession;\n        internal IntPtr OverlayPtr;\n        private readonly Texture[] textures;\n\n        public unsafe OculusOverlay(IntPtr ovrSession, GraphicsDevice device, int width, int height, int mipLevels, int sampleCount)\n        {\n            this.ovrSession = ovrSession;\n\n            OverlayPtr = OculusOvr.CreateQuadLayerTexturesDx(ovrSession, (nint) device.NativeDevice.Handle, out var textureCount, width, height, mipLevels, sampleCount);\n            if (OverlayPtr == IntPtr.Zero)\n            {\n                throw new Exception(OculusOvr.GetError());\n            }\n\n            textures = new Texture[textureCount];\n            for (var i = 0; i < textureCount; i++)\n            {\n                var dxTexture2D = (ID3D11Texture2D*) OculusOvr.GetQuadLayerTextureDx(ovrSession, OverlayPtr, OculusOvrHmd.Dx11Texture2DGuid, i);\n                if (dxTexture2D is null)\n                {\n                    throw new Exception(OculusOvr.GetError());\n                }\n\n                textures[i] = new Texture(device).InitializeFromImpl(dxTexture2D, 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                dxTexture2D->Release();\n            }","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.VirtualReality/OculusOVR/OculusOverlay.cs#L7-L43","documentation":"OculusOverlay's constructor calls OculusOvr.CreateQuadLayerTexturesDx to create the LibOVR quad-layer swapchain bound to the app's D3D11 device. If the native call fails it returns a null overlay pointer, and the wrapper throws an Exception carrying the last LibOVR error string (ovr_GetLastError), since no richer exception type is available across the P/Invoke boundary.","triggerScenarios":"Creating an OculusOverlay when the native CreateQuadLayerTexturesDx call returns IntPtr.Zero — e.g. no active OVR session, an invalid D3D11 device handle, unsupported width/height/mipLevels/sampleCount, or the OVR runtime not being initialized.","commonSituations":"Using the Oculus backend without a headset/runtime running; creating the overlay before the HMD session is enabled; mixing D3D11 devices (passing a device from another adapter); requesting invalid texture parameters.","solutions":["Ensure the Oculus OVR session is created and the HMD is enabled (OculusOvrHmd.Enable) before constructing the overlay.","Verify the GraphicsDevice is a D3D11 device and its native handle is passed correctly.","Check width/height/mipLevels/sampleCount are within device limits reported by the runtime.","Confirm the Oculus runtime software is installed and running; read the returned error string for the native cause."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// C#\nbool ready = hmd != null && hmd.State == VRState.Ready && GraphicsDevice.GraphicsBackend == GraphicsBackend.Direct3D11;\n","typeGuard":null,"tryCatchPattern":"// C#\ntry { overlay = new OculusOverlay(device, session, w, h, mip, samples); }\ncatch (Exception ex) { Logger.Warning(\"Oculus overlay init failed: \" + ex.Message); overlay = null; }","preventionTips":["Create overlays only after the OVR session is established and the HMD reports Ready","Validate texture parameters against device limits before creating the overlay","Confirm the Oculus runtime is installed and running before enabling VR features"],"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"}