Skip to content

Commit 7e78636

Browse files
foxtaclesslouken
authored andcommitted
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.
1 parent f173fd2 commit 7e78636

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/video/emscripten/SDL_emscriptenvideo.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,11 @@ static bool Emscripten_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window,
812812
// Pass PNG data to JavaScript
813813
MAIN_THREAD_EM_ASM({
814814
var pngData = HEAPU8.subarray($0, $0 + $1);
815+
if (pngData.buffer instanceof SharedArrayBuffer) {
816+
// explicitly create a copy
817+
pngData = new Uint8Array(pngData);
818+
}
819+
815820
var blob = new Blob([pngData], {type: 'image/png'});
816821
var url = URL.createObjectURL(blob);
817822

0 commit comments

Comments
 (0)