Handle SharedArrayBuffer for PNG data

The Emscripten support for setting window icons introduced in #14490 does not work when using pthreads. Using `SetWindowIcon` will cause the program to crash. The reason for that is that the `Blob` constructor does not accept shared memory (`SharedArrayBuffer`).

We need to create a local copy of the icon data if necessary.
This commit is contained in:
Christian Semmler
2025-12-07 06:54:02 +01:00
committed by Sam Lantinga
parent f173fd28f0
commit 7e78636e8e

View File

@@ -812,6 +812,11 @@ static bool Emscripten_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window,
// Pass PNG data to JavaScript
MAIN_THREAD_EM_ASM({
var pngData = HEAPU8.subarray($0, $0 + $1);
if (pngData.buffer instanceof SharedArrayBuffer) {
// explicitly create a copy
pngData = new Uint8Array(pngData);
}
var blob = new Blob([pngData], {type: 'image/png'});
var url = URL.createObjectURL(blob);