upipe
upipe copied to clipboard
OpenGL function called after context destroyed
upipe_glx_sink_clean_glx is called before uprobe_gl_sink_clean, and glDeleteTextures is called inside uprobe_gl_sink_clean, which has no effect since the OpenGL context was destroyed already.
Not sure whether the following patch is appropriate or not:
diff --git a/include/upipe-gl/upipe_gl_sink_common.h b/include/upipe-gl/upipe_gl_sink_common.h
index bdd03dba..269aa1b4 100644
--- a/include/upipe-gl/upipe_gl_sink_common.h
+++ b/include/upipe-gl/upipe_gl_sink_common.h
@@ -44,6 +44,8 @@ enum uprobe_gl_sink_event {
/** init GL context (int SIGNATURE, int width, int height) */
UPROBE_GL_SINK_INIT,
+ /** terminate GL context (int SIGNATURE) */
+ UPROBE_GL_SINK_TERMINATE,
/** render GL (int SIGNATURE, struct uref*) */
UPROBE_GL_SINK_RENDER,
/** reshape GL (int SIGNATURE, int width, int height) */
diff --git a/lib/upipe-gl/uprobe_gl_sink.c b/lib/upipe-gl/uprobe_gl_sink.c
index 2a3ea0d1..55bfcbbe 100644
--- a/lib/upipe-gl/uprobe_gl_sink.c
+++ b/lib/upipe-gl/uprobe_gl_sink.c
@@ -178,6 +178,16 @@ static void uprobe_gl_sink_init2(struct uprobe *uprobe,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
+static void uprobe_gl_sink_terminate(struct uprobe *uprobe,
+ struct upipe *upipe)
+{
+ struct uprobe_gl_sink *uprobe_gl_sink = uprobe_gl_sink_from_uprobe(uprobe);
+ if (uprobe_gl_sink->texture) {
+ glDeleteTextures(1, &uprobe_gl_sink->texture);
+ uprobe_gl_sink->texture = 0;
+ }
+}
+
/** @internal @This catches events thrown by pipes.
*
* @param uprobe pointer to probe
@@ -204,6 +214,10 @@ static int uprobe_gl_sink_throw(struct uprobe *uprobe,
uprobe_gl_sink_init2(uprobe, upipe, w, h);
return UBASE_ERR_NONE;
}
+ case UPROBE_GL_SINK_TERMINATE: {
+ uprobe_gl_sink_terminate(uprobe, upipe);
+ return UBASE_ERR_NONE;
+ }
case UPROBE_GL_SINK_RENDER: {
unsigned int signature = va_arg(args, unsigned int);
assert(signature == UPIPE_GL_SINK_SIGNATURE);
@@ -248,7 +262,10 @@ uprobe_gl_sink_init(struct uprobe_gl_sink *uprobe_gl_sink,
*/
static void uprobe_gl_sink_clean(struct uprobe_gl_sink *uprobe_gl_sink)
{
- glDeleteTextures(1, &uprobe_gl_sink->texture);
+ if (uprobe_gl_sink->texture) {
+ glDeleteTextures(1, &uprobe_gl_sink->texture);
+ uprobe_gl_sink->texture = 0;
+ }
struct uprobe *uprobe = &uprobe_gl_sink->uprobe;
uprobe_clean(uprobe);
}