fix: sync #dpr immediately after controller reinit on alphaEnabled toggle#23
Merged
Conversation
…ggle When alphaEnabled (or webGPUEnabled) changes, the init effect tears down the old controller and creates a new one. The ResizeObserver only fires when the container *size* changes, so it never re-fires for a toggle — leaving the simulation with the default #dpr=1 until something else triggers a resize. With wrong #dpr the pointer-to-UV coordinate transform is off: px = (cssX * 1) / (cssW * DPR * qualityDpr) -- wrong px = (cssX * DPR * qualityDpr) / (cssW * DPR * qualityDpr) -- correct Fix: call controller.resize(initW, initH) immediately after construction so the correct DPR is pushed into the simulation from frame 0, matching the behaviour the user already sees when changing pixelRatio. Also null-guard FluidController#resize for the async WebGPU path where #sim is temporarily null while the adapter request is in flight. Closes #16 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
A fresh FluidSimulation starts with #mouse.{x,y,targetX,targetY} = 0.
The first handleMove call computes dx = currentX - 0, producing a large
velocity vector that draws a fluid streak from the top-left corner to the
cursor on every controller reinit (alphaEnabled toggle, etc.).
Fix: skip the dx/dy calculation on the very first handleMove and just seed
the mouse position instead, so subsequent moves only measure real deltas.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
alphaEnabled(orwebGPUEnabled) is toggledFluidController, but theResizeObserveronly fires when the container dimensions change — not when onlyalphaEnabledchanges. This leftsimulation.#dpr = 1(the default) so the pointer-to-UV coordinate transform was wrong until something else triggered a resizecontroller.resize(initW, initH)right after construction inuseFluid.tsto push the correct DPR into the simulation from frame 0FluidController#resize(!→?) for the async WebGPU path where#simis temporarilynullwhile the adapter request is in flightTest plan
npm test -- --run)npm run build)alphaEnabledoff — cursor and splat should be co-locatedalphaEnabledback on — still correctpixelRatio/simResolutionquality changesCloses #16
🤖 Generated with Claude Code