Skip to content

Commit c00a68f

Browse files
committed
Merge pull request #1971 from jvilk/sdl_fixes
[SDL] Fixing SDL_UnlockSurface in IE10/IE11
2 parents a8e2604 + 2268e7b commit c00a68f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/library_sdl.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -1056,14 +1056,28 @@ var LibrarySDL = {
10561056
var buffer = surfData.buffer;
10571057
#if USE_TYPED_ARRAYS == 2
10581058
assert(buffer % 4 == 0, 'Invalid buffer offset: ' + buffer);
1059-
var src = buffer >> 2;
1059+
var src;
10601060
var dst = 0;
10611061
var isScreen = surf == SDL.screen;
1062-
var data32 = new Uint32Array(data.buffer);
1063-
var num = data32.length;
1064-
while (dst < num) {
1065-
// HEAP32[src++] is an optimization. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}};
1066-
data32[dst++] = HEAP32[src++] | (isScreen ? 0xff000000 : 0);
1062+
var num;
1063+
if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) {
1064+
// IE10/IE11: Canvases are backed by the deprecated CanvasPixelArray,
1065+
// not UInt8ClampedArray. These don't have buffers, so we need to revert
1066+
// to copying a byte at a time. We do the undefined check because modern
1067+
// browsers do not define CanvasPixelArray anymore.
1068+
src = buffer;
1069+
num = data.length;
1070+
while (dst < num) {
1071+
data[dst++] = HEAP8[src++];
1072+
}
1073+
} else {
1074+
var data32 = new Uint32Array(data.buffer);
1075+
src = buffer >> 2;
1076+
num = data32.length;
1077+
while (dst < num) {
1078+
// HEAP32[src++] is an optimization. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}};
1079+
data32[dst++] = HEAP32[src++] | (isScreen ? 0xff000000 : 0);
1080+
}
10671081
}
10681082
#else
10691083
var num = surfData.image.data.length;

tests/sdl_canvas.c

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ int main(int argc, char **argv) {
6262

6363
printf("you should see two lines of text in different colors and a blue rectangle\n");
6464

65+
SDL_UnlockSurface(screen);
66+
6567
SDL_Quit();
6668

6769
printf("done.\n");

0 commit comments

Comments
 (0)