{"record":{"id":"26be95942ee73a61","repo":"babalae/better-genshin-impact","slug":"timeout-0","errorCode":null,"errorMessage":"timeout 必须大于 0","messagePattern":"timeout 必须大于 0","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Core/BgiVision/BvLocator.cs","lineNumber":277,"sourceCode":"            RetryAction = (results) =>\n            {\n                action(results);\n                return Task.CompletedTask;\n            };\n        }\n        return this;\n    }\n\n    /// <summary>\n    /// 设置超时时间（毫秒）\n    /// </summary>\n    /// <param name=\"timeout\">超时时间（毫秒）</param>\n    /// <returns></returns>\n    public BvLocator WithTimeout(int timeout)\n    {\n        if (timeout <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(timeout), \"timeout 必须大于 0\");\n        }\n        _timeout = timeout;\n        return this;\n    }\n\n    /// <summary>\n    /// 设置重试间隔（毫秒）\n    /// </summary>\n    /// <param name=\"retryInterval\">重试间隔（毫秒）</param>\n    /// <returns></returns>\n    public BvLocator WithRetryInterval(int retryInterval)\n    {\n        if (retryInterval <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(retryInterval), \"retryInterval 必须大于 0\");\n        }\n        _retryInterval = retryInterval;\n        return this;","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/BgiVision/BvLocator.cs#L259-L295","documentation":"Thrown by HtmlMaskWindow.Show when the count of already-open HTML mask windows reaches MaxWindows (5). HtmlMaskWindow manages a static ConcurrentDictionary of active overlay windows; exceeding the cap prevents resource exhaustion from too many WebView2 instances. The exception is InvalidOperationException thrown on the UI dispatcher thread.","triggerScenarios":"HtmlMaskWindow.Show is called while _windows.Count >= 5. The per-id replacement logic (closing existing window with same id) runs first, so this triggers only when there are 5 windows with distinct ids and a new unique-id window is requested.","commonSituations":"A script opens multiple HTML overlays without closing previous ones, a bug leaks windows (Closed handler didn't fire so _windows wasn't pruned), or a script loops creating overlays without cleanup.","solutions":["Close unneeded windows via HtmlMaskWindow.Close(id) or CloseAll() before opening new ones.","Reuse existing window ids to replace rather than accumulate windows.","Audit that the Closed event handler reliably removes entries from _windows (check for disposal/exception leaks).","Catch InvalidOperationException in the caller and present a user message to close existing overlays."],"exampleFix":"// before\nif (_windows.Count >= MaxWindows)\n    throw new InvalidOperationException($\"最多同时打开 {MaxWindows} 个HTML遮罩窗口\");\n\n// after — auto-close oldest window or return error id\nif (_windows.Count >= MaxWindows)\n{\n    var oldest = _windows.Values.OrderBy(w => w._createdAt).FirstOrDefault();\n    oldest?.Close();\n}\nif (_windows.Count >= MaxWindows)\n    return string.Empty; // caller checks for empty id\n","handlingStrategy":"validation","validationCode":"// Check window count before opening\nif (HtmlMaskWindow.ActiveCount >= 5)\n{\n    HtmlMaskWindow.CloseAll(); // or close oldest\n}\nvar id = HtmlMaskWindow.Show(url, myId, workDir);","typeGuard":"static bool CanOpenNewWindow() => _windows.Count < MaxWindows;","tryCatchPattern":"try { return HtmlMaskWindow.Show(url, id, workDir); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"MaxWindows\"))\n{ HtmlMaskWindow.CloseAll(); return HtmlMaskWindow.Show(url, id, workDir); }","preventionTips":["Reuse existing window ids to replace rather than accumulate overlays.","Close windows explicitly via Close(id) when done.","Audit the Closed event handler to ensure _windows is pruned on every disposal."],"tags":["html-mask","webview2","window-limit","resource-management"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}