Skip to content

Commit 1fbdd8e

Browse files
committed
Fix for zero count in glUniform family of functions
The previous fix for this was in emscripten-core#21567, but I looks like that only covered the new "garbage-free" webgl2 path. When old webgl1 path was still using the zero count value. For example the following line was unguarded: ``` var view = miniTempWebGLFloatBuffers[4 * count - 1]; ``` This recently resurfaced because I introduced `WEBGL_USE_GARBAGE_FREE_APIS` which is currently disabled for memories larger 2gb. This meant that users with large memories were forces onto the old path where the bug still existed. Rather than adding yet more `count &&` prefixes, this patch simply adds a single early return at the top of each function. Fixes: emscripten-core#21567
1 parent 5dbbd71 commit 1fbdd8e

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

src/library_webgl.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,17 +2421,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
24212421
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform1iv', 'location');
24222422
assert((value & 3) == 0, 'Pointer to integer data passed to glUniform1iv must be aligned to four bytes!');
24232423
#endif
2424+
if (!count) return;
24242425

24252426
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
24262427
#if GL_ASSERTIONS
24272428
assert(GL.currentContext.version >= 2);
24282429
#endif
2429-
count && GLctx.uniform1iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count);
2430+
GLctx.uniform1iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count);
24302431
#else
24312432

24322433
#if WEBGL_USE_GARBAGE_FREE_APIS
24332434
if ({{{ isCurrentContextWebGL2() }}}) {
2434-
count && GLctx.uniform1iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count);
2435+
GLctx.uniform1iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count);
24352436
return;
24362437
}
24372438
#endif
@@ -2462,17 +2463,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
24622463
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform2iv', 'location');
24632464
assert((value & 3) == 0, 'Pointer to integer data passed to glUniform2iv must be aligned to four bytes!');
24642465
#endif
2466+
if (!count) return;
24652467

24662468
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
24672469
#if GL_ASSERTIONS
24682470
assert(GL.currentContext.version >= 2);
24692471
#endif
2470-
count && GLctx.uniform2iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*2);
2472+
GLctx.uniform2iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*2);
24712473
#else
24722474

24732475
#if WEBGL_USE_GARBAGE_FREE_APIS
24742476
if ({{{ isCurrentContextWebGL2() }}}) {
2475-
count && GLctx.uniform2iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*2);
2477+
GLctx.uniform2iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*2);
24762478
return;
24772479
}
24782480
#endif
@@ -2504,17 +2506,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
25042506
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform3iv', 'location');
25052507
assert((value & 3) == 0, 'Pointer to integer data passed to glUniform3iv must be aligned to four bytes!');
25062508
#endif
2509+
if (!count) return;
25072510

25082511
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
25092512
#if GL_ASSERTIONS
25102513
assert(GL.currentContext.version >= 2);
25112514
#endif
2512-
count && GLctx.uniform3iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*3);
2515+
GLctx.uniform3iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*3);
25132516
#else
25142517

25152518
#if WEBGL_USE_GARBAGE_FREE_APIS
25162519
if ({{{ isCurrentContextWebGL2() }}}) {
2517-
count && GLctx.uniform3iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*3);
2520+
GLctx.uniform3iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*3);
25182521
return;
25192522
}
25202523
#endif
@@ -2547,17 +2550,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
25472550
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform4iv', 'location');
25482551
assert((value & 3) == 0, 'Pointer to integer data passed to glUniform4iv must be aligned to four bytes!');
25492552
#endif
2553+
if (!count) return;
25502554

25512555
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
25522556
#if GL_ASSERTIONS
25532557
assert(GL.currentContext.version >= 2);
25542558
#endif
2555-
count && GLctx.uniform4iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*4);
2559+
GLctx.uniform4iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*4);
25562560
#else
25572561

25582562
#if WEBGL_USE_GARBAGE_FREE_APIS
25592563
if ({{{ isCurrentContextWebGL2() }}}) {
2560-
count && GLctx.uniform4iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*4);
2564+
GLctx.uniform4iv(webglGetUniformLocation(location), HEAP32, {{{ getHeapOffset('value', 'i32') }}}, count*4);
25612565
return;
25622566
}
25632567
#endif
@@ -2591,17 +2595,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
25912595
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform1fv', 'location');
25922596
assert((value & 3) == 0, 'Pointer to float data passed to glUniform1fv must be aligned to four bytes!');
25932597
#endif
2598+
if (!count) return;
25942599

25952600
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
25962601
#if GL_ASSERTIONS
25972602
assert(GL.currentContext.version >= 2);
25982603
#endif
2599-
count && GLctx.uniform1fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count);
2604+
GLctx.uniform1fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count);
26002605
#else
26012606

26022607
#if WEBGL_USE_GARBAGE_FREE_APIS
26032608
if ({{{ isCurrentContextWebGL2() }}}) {
2604-
count && GLctx.uniform1fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count);
2609+
GLctx.uniform1fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count);
26052610
return;
26062611
}
26072612
#endif
@@ -2632,17 +2637,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26322637
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform2fv', 'location');
26332638
assert((value & 3) == 0, 'Pointer to float data passed to glUniform2fv must be aligned to four bytes!');
26342639
#endif
2640+
if (!count) return;
26352641

26362642
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
26372643
#if GL_ASSERTIONS
26382644
assert(GL.currentContext.version >= 2);
26392645
#endif
2640-
count && GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*2);
2646+
GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*2);
26412647
#else
26422648

26432649
#if WEBGL_USE_GARBAGE_FREE_APIS
26442650
if ({{{ isCurrentContextWebGL2() }}}) {
2645-
count && GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*2);
2651+
GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*2);
26462652
return;
26472653
}
26482654
#endif
@@ -2674,17 +2680,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26742680
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform3fv', 'location');
26752681
assert((value % 4) == 0, 'Pointer to float data passed to glUniform3fv must be aligned to four bytes!' + value);
26762682
#endif
2683+
if (!count) return;
26772684

26782685
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
26792686
#if GL_ASSERTIONS
26802687
assert(GL.currentContext.version >= 2);
26812688
#endif
2682-
count && GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*3);
2689+
GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*3);
26832690
#else
26842691

26852692
#if WEBGL_USE_GARBAGE_FREE_APIS
26862693
if ({{{ isCurrentContextWebGL2() }}}) {
2687-
count && GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*3);
2694+
GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*3);
26882695
return;
26892696
}
26902697
#endif
@@ -2717,17 +2724,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
27172724
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniform4fv', 'location');
27182725
assert((value & 3) == 0, 'Pointer to float data passed to glUniform4fv must be aligned to four bytes!');
27192726
#endif
2727+
if (!count) return;
27202728

27212729
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
27222730
#if GL_ASSERTIONS
27232731
assert(GL.currentContext.version >= 2);
27242732
#endif
2725-
count && GLctx.uniform4fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*4);
2733+
GLctx.uniform4fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*4);
27262734
#else
27272735

27282736
#if WEBGL_USE_GARBAGE_FREE_APIS
27292737
if ({{{ isCurrentContextWebGL2() }}}) {
2730-
count && GLctx.uniform4fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*4);
2738+
GLctx.uniform4fv(webglGetUniformLocation(location), HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*4);
27312739
return;
27322740
}
27332741
#endif
@@ -2765,17 +2773,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
27652773
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniformMatrix2fv', 'location');
27662774
assert((value & 3) == 0, 'Pointer to float data passed to glUniformMatrix2fv must be aligned to four bytes!');
27672775
#endif
2776+
if (!count) return;
27682777

27692778
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
27702779
#if GL_ASSERTIONS
27712780
assert(GL.currentContext.version >= 2);
27722781
#endif
2773-
count && GLctx.uniformMatrix2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*4);
2782+
GLctx.uniformMatrix2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*4);
27742783
#else
27752784

27762785
#if WEBGL_USE_GARBAGE_FREE_APIS
27772786
if ({{{ isCurrentContextWebGL2() }}}) {
2778-
count && GLctx.uniformMatrix2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*4);
2787+
GLctx.uniformMatrix2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*4);
27792788
return;
27802789
}
27812790
#endif
@@ -2809,17 +2818,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28092818
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniformMatrix3fv', 'location');
28102819
assert((value & 3) == 0, 'Pointer to float data passed to glUniformMatrix3fv must be aligned to four bytes!');
28112820
#endif
2821+
if (!count) return;
28122822

28132823
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
28142824
#if GL_ASSERTIONS
28152825
assert(GL.currentContext.version >= 2);
28162826
#endif
2817-
count && GLctx.uniformMatrix3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*9);
2827+
GLctx.uniformMatrix3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*9);
28182828
#else
28192829

28202830
#if WEBGL_USE_GARBAGE_FREE_APIS
28212831
if ({{{ isCurrentContextWebGL2() }}}) {
2822-
count && GLctx.uniformMatrix3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*9);
2832+
GLctx.uniformMatrix3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*9);
28232833
return;
28242834
}
28252835
#endif
@@ -2858,17 +2868,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28582868
GL.validateGLObjectID(GLctx.currentProgram.uniformLocsById, location, 'glUniformMatrix4fv', 'location');
28592869
assert((value & 3) == 0, 'Pointer to float data passed to glUniformMatrix4fv must be aligned to four bytes!');
28602870
#endif
2871+
if (!count) return;
28612872

28622873
#if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
28632874
#if GL_ASSERTIONS
28642875
assert(GL.currentContext.version >= 2);
28652876
#endif
2866-
count && GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*16);
2877+
GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*16);
28672878
#else
28682879

28692880
#if WEBGL_USE_GARBAGE_FREE_APIS
28702881
if ({{{ isCurrentContextWebGL2() }}}) {
2871-
count && GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*16);
2882+
GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, {{{ getHeapOffset('value', 'float') }}}, count*16);
28722883
return;
28732884
}
28742885
#endif

0 commit comments

Comments
 (0)