Skip to content

Commit 08775a3

Browse files
authored
[WebGL] blitOffscreenFramebuffer: handle already-deleted program (#23980)
See comment for explanation. Issue: #23654 See the other PR for additional discussion: #23658 (comment)
1 parent 59379eb commit 08775a3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/lib/libwebgl.js

+5
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,11 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
993993

994994
var prevProgram = gl.getParameter(0x8B8D /*GL_CURRENT_PROGRAM*/);
995995
gl.useProgram(context.blitProgram);
996+
// If prevProgram was already marked for deletion, then, since it was
997+
// still bound, it was not *actually* deleted. Binding a new program
998+
// just now, thus, deleted the old one. This makes it impossible to
999+
// restore. Hopefully the application didn't actually need it!
1000+
if (!gl.isProgram(prevProgram)) prevProgram = null;
9961001

9971002
var prevVB = gl.getParameter(0x8894 /*GL_ARRAY_BUFFER_BINDING*/);
9981003
gl.bindBuffer(0x8892 /*GL_ARRAY_BUFFER*/, context.blitVB);

test/browser/webgl_draw_triangle.c

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* found in the LICENSE file.
66
*/
77

8+
#include <assert.h>
89
#include <stdio.h>
910
#include <stdlib.h>
1011
#include <emscripten/emscripten.h>
@@ -104,8 +105,13 @@ int main() {
104105
glDrawArrays(GL_TRIANGLES, 0, 3);
105106

106107
#ifdef EXPLICIT_SWAP
108+
// Mark the program for deletion, first, as a regression test for the state
109+
// restoration. https://github.com/emscripten-core/emscripten/issues/23654
110+
glDeleteProgram(program);
111+
107112
emscripten_webgl_commit_frame();
108113
#endif
109114

115+
assert(glGetError() == GL_NO_ERROR);
110116
return 0;
111117
}

0 commit comments

Comments
 (0)