SDL
SDL copied to clipboard
Emscripten_UpdateWindowFramebuffer fails if pixel data is higher than 2gb in address space
Specifically the line var src = pixels >> 2 needs updating.
It should probably be:
#if __wasm64__
var src = pixels / 4;
#else
var src = pixels >>> 0;
#endif
(I can work look into uploading a PR for this)
Yes, please send a PR when you get a chance; this feels like something I'll get wrong if I try to do it myself. :)
https://github.com/libsdl-org/SDL/blob/cd197be53b05f952900d9ff900770b3afd52ef4a/src/video/emscripten/SDL_emscriptenframebuffer.c#L92
Trying to understand the issuepixels is a void* (I guess of size either 4 or 8 depending on it being a wasm64) and HEAP32 sees the memory like a sequence of 32-bit int. The SDL_Surface->pixels is allocated using SDL_SIMDAlloc which takes the size in bytes.
>>> 0 is a trick to cast to 32-bit int, it's a weird change assuming the current >> 2 is working (this is the same as / 4 here?)
Sorry I meant to write >>> 2. The triple right shift is an unsigned shift (which is want) and the double right shift is a signed shift (which don't work for 32-bit addresses in the upper half of the range).
If this is not in performance critical code you could just use a divide by 4 operation in all cases and keep the code simple.
Just coming back to this, do we just need that one var src = pixels >> 2; line fixed? I'll put that in revision control today if so!
Any place >> or >>> is used on a pointer value would need to be fixed. I don't know if var src = pixels >> 2 is the only one.