Skip to content

fix: guard fluid mousemove while canvas is hidden (wallpaper mode) - #5

Open
Cyber-Yu-Git wants to merge 1 commit into
WYH66666666:mainfrom
Cyber-Yu-Git:fix/fluid-nan-guard
Open

fix: guard fluid mousemove while canvas is hidden (wallpaper mode)#5
Cyber-Yu-Git wants to merge 1 commit into
WYH66666666:mainfrom
Cyber-Yu-Git:fix/fluid-nan-guard

Conversation

@Cyber-Yu-Git

Copy link
Copy Markdown

问题 / Bug

背景切到「壁纸」之后,aqua.module.cssdisplay: none 隐藏流体画布,但 fluid-shader.ts 里挂在 window 上的 mousemove 监听仍在运行:

const rect = canvas.getBoundingClientRect()          // display:none → 0×0
pointer.x = (event.clientX - rect.left) / rect.width // 除以 0 → NaN

NaN 进入 flow shader 的 ping-pong 纹理后永不衰减(NaN × decay = NaN),整个流体模拟被永久污染。切回「流体」之后水不再流动、也不再跟随鼠标,只能刷新页面(重新挂载)恢复。

复现 / Repro

  1. 打开流体背景,确认水跟手正常
  2. 设置 → 外观 → 背景切换为「壁纸」
  3. 在页面上移动鼠标
  4. 切回「流体」→ 水流/跟手效果消失

修复 / Fix

  • onMouseMove 在画布 rect 为 0 时跳过指针更新,NaN 不再进入模拟
  • 渲染循环在画布零尺寸时整帧跳过(顺带省 GPU)

改动两处:src/client/fluid-shader.ts(源码)与 lib/client.js(已发布 bundle,与 src 改动逐行一致;本环境没有 tsdown 构建链,可直接用 src diff 重建 bundle)。

验证 / Verification

无头 Chromium 完整复现「隐藏画布 → 移动鼠标 → 恢复画布」流程,修复后流体正常渲染、持续动画,控制台无报错。

When background is wallpaper, aqua.module.css hides the fluid canvas with
display:none. The window-level mousemove listener kept dividing by the
canvas rect (0x0) and fed NaN/Infinity pointer coordinates into the flow
shader. NaN never decays in the ping-pong flow texture, permanently
poisoning the simulation: after switching back to fluid the water no
longer flows or follows the pointer.

- skip pointer updates while the canvas rect is empty
- skip the GL frame entirely while the canvas has zero size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant