Skip to content

Skia: native-element clip path cache is static, so it is shared across windows and raced by per-window render threadsΒ #24122

Closed as duplicate

Description

@MartinZikmund

Current behavior πŸ›

CompositionTarget's native-element clip cache is static, but every piece of state it caches belongs to a single composition target β€” i.e. to a single window:

// src/Uno.UI/UI/Xaml/Media/CompositionTarget.Rendering.skia.cs:59-62
private Size _lastCanvasSize = Size.Empty;
private static SKPath? _lastNativeClipPath;      // <-- static
private float _lastRasterizationScale = 1;
private static SKPath? _lastScaledNativeClipPath; // <-- static

The two neighbours under the same comment are instance fields, and the static pair is used exactly like them:

  • invalidated by a per-target event β€” a canvas recreation nulls the scaled path (:304),
  • keyed on this target's frame β€” _lastNativeClipPath != lastRenderedFrame.nativeElementClipPath (:348).

Consequences with more than one window open:

  1. Cross-window cache corruption. Recreating window A's canvas nulls window B's cached scaled path, and two windows with different clip paths invalidate each other on every frame. The scaled path returned at :359 can describe the wrong window's native elements.
  2. A data race on every Skia host that renders each window on its own thread (Win32, X11, and macOS once feat(macos): Dedicated Metal render threadΒ #23594 lands). One render thread can be at _lastScaledNativeClipPath = new() (:350) while another transforms into it (:354) or returns it (:359) β€” a torn or empty SKPath handed to the native clipping layer (on macOS, uno_window_clip_svg).

This is why it has gone unnoticed: with a single window there is one composition target, so static and instance behave identically.

Expected behavior 🎯

Each composition target caches its own scaled clip path, so native-element clipping in one window is unaffected by another, and concurrent per-window render threads do not share a mutable SKPath.

How to reproduce it (as minimally and precisely as possible) πŸ”¬

Open two windows that both host native elements with different clip geometry (e.g. two instances of the ContentPresenter/ContentPresenter_NativeEmbedding_ZIndex sample, or a WebView2/MediaPlayerElement in each), and animate or resize one. The other window's native-element clipping is recomputed against the wrong cache.

Code inspection is the primary evidence; the race is timing-dependent and does not reproduce deterministically.

Workaround πŸ› οΈ

None.

Renderer 🎨

Skia (all desktop targets)

Affected platforms πŸ“±πŸ’»πŸ–₯️

Skia Desktop (Windows/Win32, Linux/X11, macOS)

Activity

  1. added
    triage/untriaged
    on Aug 19, 2026
  2. MartinZikmund commented on Oct 14, 2026

    @MartinZikmund
    MemberAuthor

    Closing as a duplicate of #24239. Any details that were only here have been copied over to #24239.

  3. Jen-Uno commented on Oct 28, 2026

    @Jen-Uno
    Contributor

    This issue was closed as a duplicate, so there is nothing for QA to verify. Moving it from Ready for QA Review to Done on the Uno Team Backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions