[Bug] 150% 缩放下,中文模式输入 1. 会导致记事本等程序崩溃
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 50/100
Research direction
Start with the vertical layout height calculation in WeaselUI/VerticalLayout.cpp and WeaselUI/Layout.cpp, where spacing is subtracted even when no preedit or candidate height is added. WeaselPanel.cpp and d2d.cpp show how a non-positive size reaches the D2D resize. Reproduce on Windows at 150% scaling with inline preedit, no candidates, and the input 1.. Done means the empty-candidate layout never produces a negative or unsigned-overflow height, and the host app no longer crashes.
Written by the indexing model from the issue text.
Description
上报前请检查
- 已检索现有 issue,暂未找到明确相同根因的报告。
- 小狼毫来自官方发布页。
- 使用的是当前官方每夜版,commit 为
f96ed24。
操作系统信息
- Windows 11 专业版 26H2,
26300.9818,x64。 - 小狼毫:
0.17.4.98.f96ed24,官方 Nightly Build。 - librime:
1.17.0。 - 输入方案:万象
18.1.7,自然码。 - 显示缩放:150%,记事本窗口实际 DPI 为 144。
升级后已经重启 Windows,并确认记事本加载的是对应版本的 weasel.dll。
描述遇到的问题
我在万象方案的中文输入模式下发现,输入 1. 时,持有输入框的程序会直接崩溃。多个软件里都遇到了这个问题,下面使用记事本复现。本机记事本中可以稳定复现。
输入 1 时正常,继续按英文句点 . 后,记事本退出。小狼毫算法服务本身仍在运行。
复现步骤
- Windows 显示缩放设为 150%,使用下面列出的样式配置。
- 打开记事本,新建空白页。
- 切换到万象方案的中文输入模式。
- 依次按主键盘的
1和.。 - 记事本崩溃。
方案中的 punctuator/digit_separators 为 ",.:"。按句点后,服务端返回的状态是 status.composing=1、ctx.preedit=.,没有候选项。
相关配置
以下是本次复现使用的相关样式参数,节选自 weasel.custom.yaml:
patch:
"style/inline_preedit": true
"style/horizontal": false
"style/vertical_auto_reverse": false
"style/layout/type": vertical
"style/layout/margin_x": 5
"style/layout/margin_y": 5
"style/layout/spacing": 10
"style/layout/hilite_padding": 5
"style/layout/border_width": 0
"style/layout/shadow_radius": 0
排查结果
进一步检查发现,问题出现在空候选窗口的布局计算和图形缓冲区调整过程中。
当前是行内预编辑、没有候选项的状态。纵向布局中没有加入预编辑文本和候选项的高度,但仍会减去一次 spacing。在 150% 缩放下,边距和间距分别取整后,窗口高度变成:
margin_y = int(5 × 1.5) = 7
spacing = int(10 × 1.5) = 15
height = 7 + 7 - 15 = -1
调试时实际捕获到,D2D::OnResize 收到的宽度为 14,高度为 0xffffffff,也就是负高度转换成了无符号整数。随后图形层返回 E_INVALIDARG (0x80070057),小狼毫抛出 ComException,最终导致宿主程序退出。
调用栈节选:
HR_Impl WeaselUtility.h:367
weasel::D2D::OnResize d2d.cpp:294
weasel::WeaselPanel::Refresh WeaselPanel.cpp:322
weasel::UI::Update WeaselUI.cpp:70
WeaselTSF::_UpdateUI CandidateList.cpp:370
WeaselTSF::_SetCompositionPosition Composition.cpp:245
相关代码位于当前 commit 的 Layout.cpp、VerticalLayout.cpp、WeaselPanel.cpp 和 d2d.cpp。
临时规避办法和对照结果
保持其他配置不变,只把 style/layout/margin_y 从 5 改为 6,重新部署后,记事本中输入 1. 就不再崩溃。
同样的缩放条件下,空窗口高度变为 2 × int(6 × 1.5) - 15 = 3。之后在记事本测试了 1.、1.23、12:34、1,234,以及正常中文输入和窗口底部输入,都正常,测试期间没有新增崩溃转储。
这组对照没有修改万象方案、Lua 或数字标点规则。
预期行为
正常输入 1.,宿主程序继续运行。空候选布局产生无效尺寸时,希望小狼毫能在布局或渲染入口处理,避免异常导致整个宿主程序退出。
目前只确认了上述版本、样式和 150% 缩放组合下的行为,尚未对其他缩放比例及旧版小狼毫做同条件测试。
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 878
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rime/weasel
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
不能鼠标选词OpenBug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Bug
Difficulty 3/5 1-2 days Newbie friendliness 22/100
-
Difficulty 4/5 Over a week Newbie friendliness 18/100
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9173 ·
Maintainers usually reply within 2 days
-
feature:config kind:docs os:windows toolchain:cmake triaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
arch-based bug niri
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
noctalia-dev/noctalia#5552 ·
Maintainers usually reply within 1 day