Skip to content

Commit 36853f9

Browse files
sbc100slouken
authored andcommitted
[emscripten] Fixes for data addresses above 2gb
This includes both wasm64 and wasm32 when addressing more than 2gb of memory. Fixes: #9052 (cherry picked from commit 3deb07e)
1 parent 63aff8e commit 36853f9

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

include/SDL_stdinc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ typedef uint64_t Uint64;
257257
#define SDL_PRIs64 "I64d"
258258
#elif defined(PRIs64)
259259
#define SDL_PRIs64 PRIs64
260-
#elif defined(__LP64__) && !defined(__APPLE__)
260+
#elif defined(__LP64__) && !defined(__APPLE__) && !defined(__EMSCRIPTEN__)
261261
#define SDL_PRIs64 "ld"
262262
#else
263263
#define SDL_PRIs64 "lld"

src/audio/emscripten/SDL_emscriptenaudio.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ static void FeedAudioDevice(_THIS, const void *buf, const int buflen)
3939
/* *INDENT-OFF* */ /* clang-format off */
4040
MAIN_THREAD_EM_ASM({
4141
var SDL2 = Module['SDL2'];
42+
/* Convert incoming buf pointer to a HEAPF32 offset. */
43+
#ifdef __wasm64__
44+
var buf = $0 / 4;
45+
#else
46+
var buf = $0 >>> 2;
47+
#endif
4248
var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels'];
4349
for (var c = 0; c < numChannels; ++c) {
4450
var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c);
@@ -47,7 +53,7 @@ static void FeedAudioDevice(_THIS, const void *buf, const int buflen)
4753
}
4854

4955
for (var j = 0; j < $1; ++j) {
50-
channelData[j] = HEAPF32[$0 + ((j*numChannels + c) << 2) >> 2]; /* !!! FIXME: why are these shifts here? */
56+
channelData[j] = HEAPF32[buf + (j*numChannels + c)];
5157
}
5258
}
5359
}, buf, buflen / framelen);

src/video/emscripten/SDL_emscriptenframebuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect
8989
SDL2.imageCtx = SDL2.ctx;
9090
}
9191
var data = SDL2.image.data;
92-
var src = pixels >> 2;
92+
var src = pixels / 4;
9393
var dst = 0;
9494
var num;
9595
if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) {

src/video/emscripten/SDL_emscriptenmouse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static SDL_Cursor *Emscripten_CreateCursor(SDL_Surface *surface, int hot_x, int
9898

9999
var image = ctx.createImageData(w, h);
100100
var data = image.data;
101-
var src = pixels >> 2;
101+
var src = pixels / 4;
102102
var dst = 0;
103103
var num;
104104
if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) {

0 commit comments

Comments
 (0)