fix(v3/windows): revalidate WebView2 surface on cross-GPU monitor change (#5705)#5710
Draft
taliesin-ai wants to merge 1 commit into
Draft
fix(v3/windows): revalidate WebView2 surface on cross-GPU monitor change (#5705)#5710taliesin-ai wants to merge 1 commit into
taliesin-ai wants to merge 1 commit into
Conversation
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
6f1bd78 to
1a94d00
Compare
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.
Draft — addresses #5705. I cannot test this on real dual-GPU hardware, so the behavioural fix is unverified. Details and an explicit ask for verification are below.
What the issue reports
On a dual-GPU laptop (Intel iGPU internal panel + NVIDIA dGPU external panel), dragging a Wails v3 window from one monitor to the other turns the WebView2 content permanently black. The Go process survives, but every subsequent
ExecuteScriptreturnsRESOURCE_NOT_IN_CORRECT_STATE("The group or resource is not in the correct state…"), so the frontend is dead until restart. Dragging back does not recover it.Diagnosis
I traced this against the existing DPI-transition handling and I think the issue is a genuine gap, not a regression of the recent fixes:
PutShouldDetectMonitorScaleChanges(false)(webview2/pkg/edge/chromium.go), which makes Wails responsible for reacting to monitor transitions.WM_DPICHANGEDfires, the rasterization scale is re-asserted, and the bounds are re-asserted so content re-lays-out.WM_DPICHANGEDnever fires andresyncWebviewRasterizationScale()is a no-op — so there is currently no code path that reacts to the window changing monitors at equal DPI. That is exactly the scenario where the composition surface, tied to the source monitor's GPU adapter, is left invalid.Two honest caveats on the diagnosis:
On the issue's suggested fix
The issue proposes a
WM_DISPLAYCHANGEhandler.WM_DISPLAYCHANGEis only broadcast on a resolution/topology change — it does not reliably fire when a window is dragged between monitors. So the robust detector for the drag case is tracking the window'sHMONITORacrossWM_WINDOWPOSCHANGED(which does fire during the drag). I've implemented that as the primary path, and also kept aWM_DISPLAYCHANGEhandler because on some hybrid-GPU laptops activating the dGPU for the external panel does cause a topology change.What this PR does
WM_WINDOWPOSCHANGED, when the handle changes (skipped while minimised, matching the [v3] App crashes when reopened after being minimized for 10~15 seconds on Windows #5605 reasoning), run a revalidation. Also run it onWM_DISPLAYCHANGE.NotifyParentWindowPositionChanged+ rasterization-scale resync (no-op at equal DPI) + a bounds re-assert that actually produces a delta.The part I most want review on
The revalidation action is the discriminating variable I can't test. Re-asserting the same bounds is a no-op (WebView2 early-outs on an unchanged rect — this is also why #5677 only re-asserts bounds after a scale change made layout stale). So I nudge the bounds by 1px and restore them to force a real re-layout / surface revalidation. That's the least-risky action that might actually do something, but I genuinely don't know whether it's enough to rebuild a composition surface stranded on a dead adapter.
Escalations, in increasing order of effectiveness and regression risk, that a hardware owner could try by editing
revalidateWebviewForNewMonitor:controller.PutIsVisible(false)thentrue. More likely to force the compositor to re-attach, but risks a visible flash on every monitor crossing for all users.Testing
windows/amd64andwindows/arm64;go vetshows only pre-existingunsafe.Pointernotes. Behaviour is unverified — I have no dual-GPU Windows machine.Ask
@Lirt (#5705 reporter) and @qq540491950 — could you build this branch and confirm whether the 1px-nudge recovery clears the black screen on your hardware? If it doesn't, trying the visibility toggle (one-line change, noted in the code comment) would tell us whether a stronger surface reset is required. Maintainers: happy to reshape the recovery action or gate the visibility toggle behind an opt-in if that's the direction preferred.