Browse Source

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.
Christian Semmler 1 week ago
parent
commit
7e78636e8e
1 changed files with 5 additions and 0 deletions
  1. 5 0
      src/video/emscripten/SDL_emscriptenvideo.c

+ 5 - 0
src/video/emscripten/SDL_emscriptenvideo.c

@@ -812,6 +812,11 @@ static bool Emscripten_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window,
     // Pass PNG data to JavaScript
     // Pass PNG data to JavaScript
     MAIN_THREAD_EM_ASM({
     MAIN_THREAD_EM_ASM({
         var pngData = HEAPU8.subarray($0, $0 + $1);
         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 blob = new Blob([pngData], {type: 'image/png'});
         var url = URL.createObjectURL(blob);
         var url = URL.createObjectURL(blob);