Skip to content

[WebGL] blitOffscreenFramebuffer: handle already-deleted program #23980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/lib/libwebgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,11 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};

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

var prevVB = gl.getParameter(0x8894 /*GL_ARRAY_BUFFER_BINDING*/);
gl.bindBuffer(0x8892 /*GL_ARRAY_BUFFER*/, context.blitVB);
Expand Down
6 changes: 6 additions & 0 deletions test/browser/webgl_draw_triangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* found in the LICENSE file.
*/

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <emscripten/emscripten.h>
Expand Down Expand Up @@ -104,8 +105,13 @@ int main() {
glDrawArrays(GL_TRIANGLES, 0, 3);

#ifdef EXPLICIT_SWAP
// Mark the program for deletion, first, as a regression test for the state
// restoration. https://github.com/emscripten-core/emscripten/issues/23654
glDeleteProgram(program);

emscripten_webgl_commit_frame();
#endif

assert(glGetError() == GL_NO_ERROR);
return 0;
}