{"record":{"id":"39cd89339bdefa1f","repo":"babalae/better-genshin-impact","slug":"error-39cd89","errorCode":null,"errorMessage":"临时解除本地鼠标限制失败","messagePattern":"临时解除本地鼠标限制失败","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Monitor/LocalCursorCapture.cs","lineNumber":91,"sourceCode":"        _appliedBounds = bounds;\n        if (!_isRestrictionApplied)\n        {\n            HideCursor();\n            _isRestrictionApplied = true;\n        }\n    }\n\n    internal void ReleaseTemporarily()\n    {\n        ObjectDisposedException.ThrowIf(_isDisposed, this);\n        if (!_isCaptureSessionActive || !_isRestrictionApplied)\n        {\n            return;\n        }\n\n        if (!NativeMethods.ReleaseClipCursor(IntPtr.Zero))\n        {\n            throw new Win32Exception(\n                Marshal.GetLastWin32Error(),\n                \"临时解除本地鼠标限制失败\");\n        }\n\n        var centerX = _appliedBounds.Left + _appliedBounds.Width / 2;\n        var centerY = _appliedBounds.Top + _appliedBounds.Height / 2;\n        if (!NativeMethods.SetCursorPos(centerX, centerY))\n        {\n            logger.LogWarning(\n                \"将本地鼠标移动到桌面分身控件中心失败，Win32Error: {Win32Error}\",\n                Marshal.GetLastWin32Error());\n        }\n\n        RestoreCursorVisibility();\n        _isRestrictionApplied = false;\n        _appliedBounds = Rectangle.Empty;\n    }\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Monitor/LocalCursorCapture.cs#L73-L109","documentation":"LocalCursorCapture.ReleaseTemporarily calls the Win32 ClipCursor(NULL) to lift the local cursor restriction. If the native call fails it throws a Win32Exception carrying Marshal.GetLastPInvokeError(). This is a genuine OS-level failure (e.g. permission, session state) rather than a caller-input problem; the method only attempts the call when a restriction was previously applied.","triggerScenarios":"ClipCursor(NULL) returning false because the process lacks access in the current desktop/session; calling release during session shutdown; antivirus/hook interference intercepting ClipCursor.","commonSituations":"Running under a restricted desktop or via RDP/remote session where cursor clipping is policy-limited; third-party overlay tools conflicting; UAC/elevation boundary differences.","solutions":["Wrap the release call in try/catch (Win32Exception) and log the native error code.","Verify the process runs in an interactive desktop session with normal privileges.","Disable other cursor-clipping/overlay tools that may conflict."],"exampleFix":"// before\n_cursorCapture.ReleaseTemporarily();\n\n// after\ntry\n{\n    _cursorCapture.ReleaseTemporarily();\n}\ncatch (Win32Exception ex)\n{\n    logger.LogWarning(\"释放鼠标限制失败 Win32Error={Code}\", ex.NativeErrorCode);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    _cursorCapture.ReleaseTemporarily();\n}\ncatch (System.ComponentModel.Win32Exception ex)\n{\n    logger.LogWarning(\"释放鼠标限制失败 Win32Error={Code}\", ex.NativeErrorCode);\n    // continue; cursor restriction may already be gone\n}","preventionTips":["Always wrap native cursor calls in try/catch(Win32Exception).","Run in an interactive desktop session with normal privileges.","Disable conflicting cursor-clipping/overlay tools."],"tags":["mouse","win32","clipcursor","win32exception","monitor"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}