Skip to content

fix(composition): Guarantee a frame for every render request, without a stall recovery (backport #25941) - #26271

Closed
mergify[bot] wants to merge 15 commits into
release/stable/7.0from
mergify/bp/release/stable/7.0/pr-25941
Closed

mergify[bot] wants to merge 15 commits into
release/stable/7.0from
mergify/bp/release/stable/7.0/pr-25941

Conversation

@mergify

@mergify mergify Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #25303

PR Type:

🐞 Bugfix

What changed? 🚀

A Debug build on Skia Android (Vulkan) could abort at a slow cold start, on Debug.Assert(details.renderAction is null) in NativeDispatcher.EnqueueRender (#25303).

Cause. CompositionTarget.IsRenderRequestStalled re-asked the host for a frame after 2 s without one, and re-armed the frame handshake. At a cold start the host had simply not produced a frame for a few seconds while the UI thread was busy, so the render queued by the previous frame was still pending. The next frame then queued a second render for the same target, which is what the assert rejects.

The recovery dates from the Apple/Android lanes hanging on animations (79d8c7820f). It turned out a host was not losing frames: CompositionTarget itself never asked for one after an ahead-of-time paint, which eff8d1cb41 fixed. The recovery stayed as a safety net.

This PR removes it. Instead, every host now guarantees the contract it was covering: once InvalidateRender() is called for a live window, the host eventually calls OnNativePlatformFrameRequested. With no recovery re-arming the handshake, "one queued render per target" is a real invariant again and the assert stays.

I audited every host against that contract (Android, iOS/tvOS, macOS, Win32, X11, WebAssembly, Linux framebuffer DRM and software, Headless). The gaps it found are fixed in separate commits:

Commit Gap
fix(composition) A request made before the window's host registered latched with nobody asked; XamlRootMap.Register now asks the new host for it (CompositionTarget.OnHostAttached). After a renderer swap, the request merged into one latched for the old renderer; the host is now asked directly. It goes through the same AskHostForFrame(); #25901 takes this version when it rebases.
fix(framebuffer) DRM: the page-flip handler returned to idle with an unconditional write, discarding a request that arrived mid-flip. A failed frame dropped a pending request. poll is retried on EINTR instead of throwing on the page-flip thread. A flip completion that finds no flip in flight now throws (logged by the handler) instead of spinning.
fix(framebuffer) DRM drew inline in InvalidateRender, so any caller (a property setter, layout, Register) could receive a rendering exception. Only the page-flip thread draws now: a request made while idle wakes it through an eventfd it polls alongside the card.
fix(wasm) _pendingInvalidate was cleared before the readiness checks and left set if the JS interop threw, either consuming a request without a frame or blocking all later ones. It is now cleared only when the frame is delivered.
fix(x11) The frame pacer is created before the host registers, which the register-time ask needs. Events another thread's round trip read into Xlib's queue (Expose, but also input) waited for the next unrelated socket event; the queue is now checked before each poll.
fix(win32) Requests made between registration and graphics negotiation hit _renderThread?.SignalNewFrame() while the thread was null. One frame is now signalled when the thread starts.
fix(macos) The software and external-present draw paths returned before initialization without re-arming. This is latent today.
fix(headless) The window registered before its renderer existed, so the register-time ask would hit a null renderer. It now registers last.
fix(rendering) Frames the host called back for but dropped before presenting were never asked for again. Win32 and X11 Vulkan (the first frame after a resize) now signal their render thread / frame pacer again, and UIKit Metal (no drawable) keeps its display link running another tick. macOS has no such path: its external present only runs the software context, and Metal/WebGPU already retry on the render thread.
refactor(composition) Removes IsRenderRequestStalled's re-ask and handshake re-arm.
feat(composition) Keeps its warning, log-only: a request outstanding for over 2 s is reported (at most every 5 s, 3 times per stall), so a host that breaks the contract is diagnosable.

Apart from the UIKit dropped present above, the audit found no gap on Android or iOS/tvOS that this PR must close.

Not in this PR (follow-up found by the same audit): an exception in a frame ends the render loop on X11, UIKit Metal and the Android GL canvas. That is a bug to fix on its own; the stall warning makes it visible.

Validation

  • Compile: Uno.UI, Uno.UI.Runtime.Win32, .X11, .MacOS, .Linux.FrameBuffer and .WebAssembly.Browser build with analyzers on, with no warnings in the changed files.
  • Win32 desktop (runtime): Given_CompositionTarget, Given_AnimatedVisualPlayer, Given_Storyboard, Given_DoubleAnimation, Given_RenderTargetBitmap and Given_Window.
    • 81 of 86 pass, with no hangs.
    • The 3 failures are Given_Window theme tests that fail the same way on master on this dark-themed machine.
  • WebAssembly, headless Edge (runtime): Given_CompositionTarget, Given_AnimatedVisualPlayer and Given_Storyboard: 46 pass, 0 fail.
  • Review fixes (compile only): the headless, dropped-present, warning and DRM page-flip-thread changes build with analyzers on (Uno.UI, .Win32, .X11, .Linux.FrameBuffer); the UIKit change is left to CI.
  • Not run locally: X11, DRM, macOS, iOS and Android. No new automated test: the DRM race and the registration ordering are not deterministic to reproduce.

PR Checklist ✅

🤖 Generated with Claude Code


This is an automatic backport of pull request #25941 done by [Mergify](https://mergify.com).

ramezgerges and others added 15 commits November 9, 2026 23:03
A request made before the window's host registered, or latched for a renderer that was then replaced, was never answered.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 566270f)
The flip handler returned to idle with an unconditional write, discarding a request made in between, and a failed frame dropped one too. poll is also retried on EINTR.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit e006b45)
…ered

A frame that could not be scheduled, or was skipped while the GPU caught up, left the request consumed or the latch stuck.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 77e1975)
The pacer now exists before the host registers, and events that another thread read into Xlib's queue are handled without waiting for the next socket event.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit e0c5aca)
The window can be asked for frames before graphics negotiation creates the thread, and those requests had nothing to signal.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 184a749)
The display pass consumes needsDisplay, so skipping the frame without re-arming lost the request.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 1047651)
Every host now answers a request with a frame, so re-asking after 2 s only re-requested renders still queued, which tripped NativeDispatcher's one-render-per-target assert (fixes #25303).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 8e7f7ee)
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 1e2deb0)
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 2c6f0db)
Win32 and X11 Vulkan drop the first frame after a resize, and UIKit Metal
one with no drawable; each now asks its platform for another frame.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit e9d00fb)
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 73eb19f)
A request no longer draws inline: it wakes the page-flip thread through an
eventfd when idle, so InvalidateRender never throws into its caller.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 3d8604e)
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit c3e279d)
An idle window gets no frames, so measuring from the last one reported
a request that was milliseconds old as outstanding for seconds.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit c459608)
The frame dropped after a resize draws the old recording; the re-record
it triggers already asks for the next frame, and re-asking early could
present that old recording into the resized swapchain.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 6fe4f36)
@github-actions github-actions Bot added platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/x11 🐧 Categorizes an issue or PR as relevant to X11 labels Nov 9, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 244996 did not find any UI Test snapshots differences.

@mergify

mergify Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request is closed, so it cannot be queued. Reopen it to get the box back.

@agneszitte

Copy link
Copy Markdown
Member

Closing: #25941 reached release/stable/7.0 through the master sync #26251. Every line this backport adds is on the branch now.

@agneszitte agneszitte closed this Nov 11, 2026
@MartinZikmund
MartinZikmund deleted the mergify/bp/release/stable/7.0/pr-25941 branch November 12, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform platform/x11 🐧 Categorizes an issue or PR as relevant to X11

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants