You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SKSwapChainPanel text/image rendering breaks when Emscripten MAXIMUM_MEMORY is set to 4GB #23368
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).
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) 🔬
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:
<TargetName="PatchWebGLFor4GB"AfterTargets="Build;Publish"Condition="'$(TargetFramework)' == 'net10.0-browserwasm'">
<ItemGroup>
<_WebGlNativeJsInclude="$(OutputPath)wwwroot\_framework\dotnet.native.*.js" />
<_WebGlNativeJsInclude="$(PublishDir)wwwroot\_framework\dotnet.native.*.js"Condition="'$(PublishDir)' != ''" />
</ItemGroup>
<MSBuildProjects="$(MSBuildProjectFullPath)"Targets="_PatchWebGLFile"Properties="_WebGLFile=%(_WebGlNativeJs.FullPath);TargetFramework=$(TargetFramework)" />
</Target>
<TargetName="_PatchWebGLFile">
<PropertyGroup>
<_Js>$([System.IO.File]::ReadAllText($(_WebGLFile)))</_Js>
<_AlreadyPatched>$(_Js.Contains('GL.unpackRowLength = param'))</_AlreadyPatched>
</PropertyGroup>
<PropertyGroupCondition="'$(_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. -->
<WriteLinesToFileCondition="'$(_AlreadyPatched)' == 'false'"File="$(_WebGLFile)"Lines="$([MSBuild]::Escape($(_Js)))"Overwrite="true" />
<MessageCondition="'$(_AlreadyPatched)' == 'false'"Importance="high"Text="[webgl-4gb] backported GL_UNPACK_ROW_LENGTH fix (emscripten #21980) into $(_WebGLFile)" />
<MessageCondition="'$(_AlreadyPatched)' != 'false'"Importance="normal"Text="[webgl-4gb] already present (emscripten >= 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.
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
Activity
Jani-z commentedon Jun 2, 2026
I have just tested
SKCanvasElementwithSkiaRenderer;sinceSKSwapChainPanelis not available withSkiaRendererand even there this bug occur:ramezgerges commentedon Jun 3, 2026
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:
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.
Jani-z commentedon Jun 5, 2026
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