Skip to content

SKSwapChainPanel text/image rendering breaks when Emscripten MAXIMUM_MEMORY is set to 4GB #23368

Closed

Description

@Jani-z

Current behavior 🐛

When running a SkiaSharp-based WebAssembly app with Emscripten memory settings above 2GB, rendering issues occur in WebGL-backed views (SKSwapChainPanel).

In particular, when MAXIMUM_MEMORY is set to 4GB, text rendering becomes unstable or corrupted and image rendering may appear incorrect (for example missing text, chaotic glyph output, or color-inverted images).

Image

The issue does not occur with the same app when memory is kept at or below 2GB.

Browser console gives:
WebGL: INVALID_OPERATION: texSubImage2D: ArrayBufferView not big enough for request

Expected behavior 🎯

No response

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

A minimal repro projec: SKSwapChainPanel bug

This Bug only occures if you set Maximum Memory to 4GB

<ItemGroup> <WasmShellExtraEmccFlags Include="-s MAXIMUM_MEMORY=4GB" /> </ItemGroup>

Workaround 🛠️

  • Set MAXIMUM_MEMORY to 2GB
  • Use SKXamlCanvas instead
  • For Text its also possible to use DrawTextAsPath

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

WebAssembly

Uno.Sdk version (and other relevant versions) 📦

{
"sdk": {
"version": "10.0.300"
},
"msbuild-sdks": {
"Uno.Sdk": "6.5.33",
"Microsoft.Build.NoTargets": "3.7.134"
}
}

Also with SkiaSharp 4.x preview

IDE version 🧑‍💻

Visual Studio 2026 18.6.1

Anything else we need to know? 💬

This doesn't happens with "Uno.Sdk": "6.2.41" and Skiasharp 2.88

Activity

  1. added theissue type on Jun 2, 2026
  2. added
    triage/untriaged
    on Jun 2, 2026
  3. Jani-z commented on Jun 2, 2026

    @Jani-z
    Author

    I have just tested SKCanvasElement with SkiaRenderer; since SKSwapChainPanel is not available with SkiaRenderer and even there this bug occur:

    Image
  4. ramezgerges commented on Jun 3, 2026

    @ramezgerges
    Contributor

    This is a bug in emscripten, fixed in emscripten-core/emscripten#21980 shipped in 3.1.61, which is not yet included in the version used by the runtime (3.1.56). You can patch the final webgl js logic yourself to achieve a similar effect:

    <Target Name="PatchWebGLFor4GB"
                AfterTargets="Build;Publish"
                Condition="'$(TargetFramework)' == 'net10.0-browserwasm'">
            <ItemGroup>
                <_WebGlNativeJs Include="$(OutputPath)wwwroot\_framework\dotnet.native.*.js" />
                <_WebGlNativeJs Include="$(PublishDir)wwwroot\_framework\dotnet.native.*.js" Condition="'$(PublishDir)' != ''" />
            </ItemGroup>
            <MSBuild Projects="$(MSBuildProjectFullPath)"
                     Targets="_PatchWebGLFile"
                     Properties="_WebGLFile=%(_WebGlNativeJs.FullPath);TargetFramework=$(TargetFramework)" />
        </Target>
    
        <Target Name="_PatchWebGLFile">
            <PropertyGroup>
                <_Js>$([System.IO.File]::ReadAllText($(_WebGLFile)))</_Js>
                <_AlreadyPatched>$(_Js.Contains('GL.unpackRowLength = param'))</_AlreadyPatched>
            </PropertyGroup>
            <PropertyGroup Condition="'$(_AlreadyPatched)' == 'false'">
                <_Js>$(_Js.Replace('GL.unpackAlignment = param;', 'GL.unpackAlignment = param; } else if %28pname == 3314%29 /* GL_UNPACK_ROW_LENGTH */ { GL.unpackRowLength = param;').Replace('var plainRowSize = width * sizePerPixel;', 'var plainRowSize = %28GL.unpackRowLength || width%29 * sizePerPixel;'))</_Js>
            </PropertyGroup>
            <!-- WriteLinesToFile splits Lines on ';', so escape the content into a single item; it is unescaped on write. -->
            <WriteLinesToFile Condition="'$(_AlreadyPatched)' == 'false'"
                              File="$(_WebGLFile)"
                              Lines="$([MSBuild]::Escape($(_Js)))"
                              Overwrite="true" />
            <Message Condition="'$(_AlreadyPatched)' == 'false'" Importance="high" Text="[webgl-4gb] backported GL_UNPACK_ROW_LENGTH fix (emscripten #21980) into $(_WebGLFile)" />
            <Message Condition="'$(_AlreadyPatched)' != 'false'" Importance="normal" Text="[webgl-4gb] already present (emscripten &gt;= 3.1.61 or patched): $(_WebGLFile)" />
        </Target>

    I've tested with this target and it works. Other than this hack, the fix is to wait for a dotnet runtime version that ships with 3.1.61+ emscripten.

  5. Jani-z commented on Jun 5, 2026

    @Jani-z
    Author

    Thank you, this fix works. Just wondering when dotnet runtime update the emscripten version, because even in .NET11 preview there is still the old emscripten version

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

Metadata

Metadata

Assignees

Labels

triage/untriaged

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions