diff options
author | John Vilk <jvilk@cs.umass.edu> | 2014-01-03 15:26:47 -0500 |
---|---|---|
committer | John Vilk <jvilk@cs.umass.edu> | 2014-01-03 15:26:47 -0500 |
commit | 2268e7b0b65b532f4bc762b394e8d1c4a590fefc (patch) | |
tree | 1151e22b6fc45b4ab438c4f8b5f82c6fffc723a7 | |
parent | a1faa7ef09a250599f2a4a2e4803c4f571aa9558 (diff) |
[SDL] Fixing SDL_UnlockSurface in IE10/IE11.
Previously, just calling SDL_UnlockSurface in IE10/IE11 would throw an exception, since Emscripten assumed that the ImageData's `data` property was Uint8ClampedArray, which has a backing buffer.
IE10/IE11 still uses the deprecated CanvasPixelArray, which does not have a backing buffer property:
https://developer.mozilla.org/en-US/docs/Web/API/CanvasPixelArray
I've added an additional path to SDL_UnlockSurface for these browsers.
-rw-r--r-- | src/library_sdl.js | 26 | ||||
-rw-r--r-- | tests/sdl_canvas.c | 2 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index 1c1e8107..78f6a628 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1056,14 +1056,28 @@ var LibrarySDL = { var buffer = surfData.buffer; #if USE_TYPED_ARRAYS == 2 assert(buffer % 4 == 0, 'Invalid buffer offset: ' + buffer); - var src = buffer >> 2; + var src; var dst = 0; var isScreen = surf == SDL.screen; - var data32 = new Uint32Array(data.buffer); - var num = data32.length; - while (dst < num) { - // HEAP32[src++] is an optimization. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}}; - data32[dst++] = HEAP32[src++] | (isScreen ? 0xff000000 : 0); + var num; + if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) { + // IE10/IE11: Canvases are backed by the deprecated CanvasPixelArray, + // not UInt8ClampedArray. These don't have buffers, so we need to revert + // to copying a byte at a time. We do the undefined check because modern + // browsers do not define CanvasPixelArray anymore. + src = buffer; + num = data.length; + while (dst < num) { + data[dst++] = HEAP8[src++]; + } + } else { + var data32 = new Uint32Array(data.buffer); + src = buffer >> 2; + num = data32.length; + while (dst < num) { + // HEAP32[src++] is an optimization. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}}; + data32[dst++] = HEAP32[src++] | (isScreen ? 0xff000000 : 0); + } } #else var num = surfData.image.data.length; diff --git a/tests/sdl_canvas.c b/tests/sdl_canvas.c index 6bd659b8..cab48985 100644 --- a/tests/sdl_canvas.c +++ b/tests/sdl_canvas.c @@ -62,6 +62,8 @@ int main(int argc, char **argv) { printf("you should see two lines of text in different colors and a blue rectangle\n"); + SDL_UnlockSurface(screen); + SDL_Quit(); printf("done.\n"); |