Skip to content

SvgImageSource.SetSourceAsync(stream) returns Other and draws nothing on Skia (6.x) #25554

Open

Description

@mikernet

Current behavior 🐛

On the Skia renderer in Uno 6.7 and 6.8, await svgImageSource.SetSourceAsync(stream) returns SvgImageSourceLoadStatus.Other, nothing is drawn, and neither Opened nor OpenFailed is raised. This happens whether Image.Source is set before or after the call. The same SVG loads fine from UriSource.

SetSourceAsync subscribes to the source, which opens it, and then calls InvalidateSource(), which opens it again and cancels the first open's token. SvgImageSource caches its load (_currentOpenTask ??= LoadSvgImageAsync(ct) in SvgImageSource.provider.cs), so the load stays bound to that first, now cancelled, token. If the stream read is still pending, it gets cancelled and the load comes back empty, and the status falls back to Other. On WebAssembly this happens every time. On desktop the file read races the second open and almost always loses.

The same re-open breaks an ImageBrush whose ImageSource is an SvgImageSource with a UriSource that is still loading (for example over http): the brush stays empty.

Expected behavior 🎯

SetSourceAsync returns Success, Opened is raised and the SVG is drawn, as on WinUI.

How to reproduce it (as minimally and precisely as possible) 🔬

App with the SkiaRenderer and Svg Uno features:

var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/logo.svg"));
using var stream = await file.OpenReadAsync();

var source = new SvgImageSource();
source.Opened += (_, _) => Debug.WriteLine("Opened");          // never raised
source.OpenFailed += (_, e) => Debug.WriteLine($"Failed {e.Status}"); // never raised
MyImage.Source = source;

var status = await source.SetSourceAsync(stream); // Other, and the Image stays empty

Workaround 🛠️

Copy the SVG into a MemoryStream first. Its read finishes synchronously, before the second open:

var ms = new MemoryStream(svgBytes);
await source.SetSourceAsync(ms.AsRandomAccessStream());

Affected platforms 📱💻🖥️

WebAssembly, Android, iOS, Desktop (Windows), Desktop (macOS), Desktop (X11) (Skia renderer; seen on Windows desktop, WebAssembly and Android, and the other Skia targets run the same code)

Uno.Sdk version (and other relevant versions) 📦

Uno.Sdk 6.7.30. Also reproduced on servicing/6.8. Master is not affected: #25166 already made the SVG load independent of the open that started it.

IDE version 🧑‍💻

Not IDE related

Anything else we need to know? 💬

The native Android renderer doesn't go through this path and loads SVG streams correctly.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions