Skip to content

Commit

Permalink
[emscripten] Fixes for data addresses above 2gb
Browse files Browse the repository at this point in the history
This includes both wasm64 and wasm32 when addressing more than 2gb of
memory.

Fixes: #9052
(cherry picked from commit 3deb07e)
  • Loading branch information
sbc100 authored and slouken committed Oct 8, 2024
1 parent 63aff8e commit 36853f9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/SDL_stdinc.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ typedef uint64_t Uint64;
#define SDL_PRIs64 "I64d"
#elif defined(PRIs64)
#define SDL_PRIs64 PRIs64
#elif defined(__LP64__) && !defined(__APPLE__)
#elif defined(__LP64__) && !defined(__APPLE__) && !defined(__EMSCRIPTEN__)
#define SDL_PRIs64 "ld"
#else
#define SDL_PRIs64 "lld"
Expand Down
8 changes: 7 additions & 1 deletion src/audio/emscripten/SDL_emscriptenaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ static void FeedAudioDevice(_THIS, const void *buf, const int buflen)
/* *INDENT-OFF* */ /* clang-format off */
MAIN_THREAD_EM_ASM({
var SDL2 = Module['SDL2'];
/* Convert incoming buf pointer to a HEAPF32 offset. */
#ifdef __wasm64__
var buf = $0 / 4;
#else
var buf = $0 >>> 2;
#endif
var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels'];
for (var c = 0; c < numChannels; ++c) {
var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c);
Expand All @@ -47,7 +53,7 @@ static void FeedAudioDevice(_THIS, const void *buf, const int buflen)
}

for (var j = 0; j < $1; ++j) {
channelData[j] = HEAPF32[$0 + ((j*numChannels + c) << 2) >> 2]; /* !!! FIXME: why are these shifts here? */
channelData[j] = HEAPF32[buf + (j*numChannels + c)];
}
}
}, buf, buflen / framelen);
Expand Down
2 changes: 1 addition & 1 deletion src/video/emscripten/SDL_emscriptenframebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect
SDL2.imageCtx = SDL2.ctx;
}
var data = SDL2.image.data;
var src = pixels >> 2;
var src = pixels / 4;
var dst = 0;
var num;
if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) {
Expand Down
2 changes: 1 addition & 1 deletion src/video/emscripten/SDL_emscriptenmouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static SDL_Cursor *Emscripten_CreateCursor(SDL_Surface *surface, int hot_x, int

var image = ctx.createImageData(w, h);
var data = image.data;
var src = pixels >> 2;
var src = pixels / 4;
var dst = 0;
var num;
if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) {
Expand Down

0 comments on commit 36853f9

Please sign in to comment.