fix(windows): prevent crash on app exit caused by WinRT COM release d…#2838
Open
Y-PLONI wants to merge 6 commits into
Open
fix(windows): prevent crash on app exit caused by WinRT COM release d…#2838Y-PLONI wants to merge 6 commits into
Y-PLONI wants to merge 6 commits into
Conversation
…uring DLL unload Static WinRT/Composition objects (ICompositor, IDispatcherQueueController, GraphicsContext, RoHelper) were held in static smart pointers (winrt::com_ptr, std::unique_ptr, std::shared_ptr). Their destructors called Release() and RoUninitialize() during DLL_PROCESS_DETACH, after the WinRT DLLs had already started unloading, triggering RaiseFailFastException in KernelBase.dll and causing Windows Error Reporting to appear on exit. Changes: - Convert all four static WinRT/COM resource pointers to raw pointers so no RAII destructor runs Release() or RoUninitialize() at static-destruction time; the OS reclaims them at process exit instead. - Add instance_count_ (protected by shared_resources_mutex_) to track the number of live InAppWebViewManager instances and trigger cleanup only when the last one is destroyed. - Add detachSharedResourcesForShutdown() which nulls all raw pointers under the mutex (without delete/Release) and returns the dispatcher queue controller for subsequent use. - Add shutdownDispatcherQueue() which calls ShutdownQueueAsync() outside the mutex and intentionally leaks both the IAsyncAction and the controller as process-lifetime objects, avoiding any Release() race with WinRT teardown. - Remove the earlier AddRef() workaround on ICompositor, which did not actually prevent the crash. - Replace the std::unique_ptr/shared_ptr allocations of RoHelper and GraphicsContext with raw new, consistent with the process-lifetime-leak design for all shared resources. Fixes: pichillilorenzo#2733 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Batching scroll sends to one platform message per Flutter frame added 0-16ms of variable latency, and in a busy app a delayed or skipped UI frame held trackpad input back and then released it in a burst - scrolling that intermittently ignored the fingers and caught up a moment later. Chromium coalesces a per-event wheel stream by itself (exactly what high-resolution mouse wheels produce natively), so the frame-tied batching only added jitter. Measured with the in-repo smoothness probe (real WebView2, identical synthetic drag): end-to-end latency dropped from 81ms to 56ms and step jitter improved (stdStep 0.66px -> 0.52px, 0% stalled frames) with Chromium smooth scrolling at its default. Also stop the synthetic fling on PointerScrollInertiaCancelEvent, which the engine sends when the user touches the trackpad during inertia. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1:1 finger-to-page tracking was reported to feel sluggish compared to native precision-touchpad scrolling. Pan deltas (and synthetic fling distances, which pass through the same conversion) are now scaled by a felt gain of 1.5 on top of the measured 120-units-per-100px Chromium wheel calibration, so the page moves 1.5x the finger travel. _kTrackpadGain is the single knob for tuning scroll speed. A synthetic-touch (SendPointerInput PT_TOUCH) alternative was prototyped and measured against a real WebView2: it gives native direct manipulation and Chromium fling, but WebView2 only begins a touch scroll after ~34px of movement per gesture (282ms begin latency, gestures under ~30px scroll nothing). That dead zone kills the small precise scrolls a reading app lives on, so the wheel-injection path stays. Measured after this change (in-repo smoothness probe, real WebView2): page/finger = 1.50 exactly, 0% stalled frames, stdStep 0.44px, 42ms latency, and 8-40px micro-gestures all scroll at full gain. Co-Authored-By: Claude Fable 5 <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.
…uring DLL unload
Static WinRT/Composition objects (ICompositor, IDispatcherQueueController, GraphicsContext, RoHelper) were held in static smart pointers (winrt::com_ptr, std::unique_ptr, std::shared_ptr). Their destructors called Release() and RoUninitialize() during DLL_PROCESS_DETACH, after the WinRT DLLs had already started unloading, triggering RaiseFailFastException in KernelBase.dll and causing Windows Error Reporting to appear on exit.
Changes:
Fixes: #2733
Connection with issue(s)
Resolve issue #???
Connected to #???
Testing and Review Notes
Screenshots or Videos
To Do