Repository navigation
Conversation
Root-cause hardening for 'typing freezes / English-only / no candidate window until I switch IME' on the DirectComposition rewrite (nightly 0.17.4.98). - WeaselPanel: use a non-vsync Present(0,0) instead of the synchronous Present(1,0). DoPaint runs on the server message thread; while occluded / compositor-throttled / display asleep the sync Present can block for a long time, during which the server holds g_api_mutex and every queued IPC request from the host stalls (keys stop being eaten -> letters go straight through). - WeaselPanel/D2D: never release or recreate DeviceResources from the IPC pipe thread. Refresh() and D2D::OnResize() deferred recovery to DoPaint(), which runs on the window's own message thread, so device release/recreation is single-threaded (fixes use-after-recreate / torn frames). - DeviceResources: guard EnsureInitialized()/Reset() with a mutex. - PipeChannel: _WritePipe(_GetPipeHandle(), ...) passed a HANDLE* where a HANDLE was expected, so the post-reconnect retry always failed and skipped ClearBufferStream(); dereference it and always clear the send context. - PipeChannel: bound the client connect retry loop (~2s) instead of spinning forever on the host UI thread.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
nightly(
0.17.4.98.f96ed24)上偶发「打字卡一下 / 只出英文 / 候选窗不刷新,切一次输入法就恢复」。本 PR 修的是四处会让 UI 线程与 IPC 队列互相拖死、以及跨线程释放 D3D 设备的点;不改 IPC 协议、不改外观。问题描述与现有证据在 #1988;成因脉络(2011 消息线程 → 2018 命名管道 + 每连接线程 → 2025
g_api_mutex→ 2026-10 DComp 同步Present)也补在 #1988 的讨论里。改动(5 文件,+58 / −21)
WeaselUI/WeaselPanel.cpp:Present(1, 0)→Present(0, 0)DoPaint()跑在服务端消息线程。候选窗被遮挡 / DWM 节流 / 显示器休眠时,同步Present可能长时间不返回;这段时间管道线程正卡在Refresh() → _ResizeWindow() → SetWindowPos(跨线程同步发送)上等消息线程,而它仍持有g_api_mutex—— 该宿主后续 IPC 全部排队,宿主里的weasel.dll又在无超时的ReadFile上阻塞。改为不等垂直同步,并把DXGI_ERROR_WAS_STILL_DRAWING当正常情况忽略。WeaselPanel.cpp/WeaselUI/d2d.cpp:设备释放与重建只在消息线程Refresh()(管道线程)与D2D::OnResize()(同样由Refresh进入)原本会DeviceResources::Get().Reset()+InitDirect2D()—— 在非窗口线程释放、重建共享 D3D/DComposition 设备,而消息线程可能正同时在DoPaint()里使用它。现在这两处不再动设备,恢复统一放到DoPaint()(WM_PAINT,消息线程);同时把DoPaint()的恢复判断提前到 resource-null 守卫之前,避免「上次初始化失败后便再也不重试」。WeaselUI/d2d.{h,cpp}:DeviceResources加锁进程级单例原本无锁,
EnsureInitialized()与Reset()加std::mutex,防止两线程并发创建/释放。include/PipeChannel.h、WeaselIPC/PipeChannel.cpp:两处传输层缺陷_WritePipe(_GetPipeHandle(), …)把HANDLE*当HANDLE(形参是HANDLE)交给WriteFile,重连后的重试必然失败;且异常会跳过ClearBufferStream(),把has_body/ 写流残留进下一次发送。改为*_GetPipeHandle(),并保证异常路径也清 send-context。_Connect()的while (_Invalid(pipe = _TryConnect())) WaitNamedPipe(name, 500);无上限,且运行在宿主 UI 线程;服务端实例持续全忙时会死循环。改为约 2s 上限后放弃(退化成「这一次不吃键」,而不是冻死)。验证
fork 上以与上游相同的工具链(
windows-2022/ VS2022 v143)完整构建:成功0 Error(s)收尾,error C…/error LNK…均为 0;x64 / Win32 / ARM / ARM64 全部产出,installer 正常生成weasel-0.17.4-patched:weasel-0.17.4.100.781adef-installer.exe+debug_symbols.7z说明:上游
ci.yml里的get-rime.ps1未带 token,在 fork 环境容易撞匿名 rate limit 并静默失败(fork 的build.yml注释里记录了这个坑),所以上面的链接用的是 fork 里那份等价 workflow;本 PR 不包含该 workflow 文件。没有做的事(边界)
Show / Hide / MoveTo / _CreateLayout / Refresh全部投递回窗口线程,并用快照替代Context& / Status& / UIStyle&这些引用。那是更彻底的解法,但改动面大;降低按键延迟并修复服务生命周期通知 #1867 的作者也指出Refresh()涉及字符串引用,「不能只靠PostMessage简单搬线程」。本 PR 只做「去掉所有无界阻塞 + 去掉所有跨线程设备释放」。AttachWindow → InitDirect2D仍在管道线程(一次性、窗口尚未显示),未改动。与已有条目的关系(提 PR 前已查重)
_Connect()上限只覆盖「连接等待」这一小段,与它们同向、不冲突;若 fix(WeaselIPC, WeaselServer): 客戶端 IPC 改為有界等待,托盤刷新移至專用執行緒(#1909 後續) #1914 合入,这一处可以退让。Present(1, 0)由它引入。g_api_mutex是那次加的。