Skip to content

Commit 45f4e3d

Browse files
[Linux] Don't clear the OpenGL context when a frame has been drawn (flutter#192137)
The draw handler made a context current to draw the frame with, then cleared it, leaving no context current at all while GTK finished the frame. GTK makes the context it needs current before using OpenGL, so this doesn't need to be cleared. But GTK doesn't check that making its context current succeeded, and if it fails it carries on and uses OpenGL with no context current, which crashes. Leaving the context current means GTK still has one to fall back on when this happens, so it doesn't crash. See flutter#191775
1 parent 6dbf67f commit 45f4e3d

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎engine/src/flutter/shell/platform/linux/fl_view_renderer_opengl.cc‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ static gboolean fl_view_renderer_opengl_draw(GtkWidget* widget, cairo_t* cr) {
162162
wait_for_frame(self, window, scale_factor);
163163
}
164164

165+
// The frame is drawn from an OpenGL texture, so make a context current that
166+
// can access it. This is deliberately not cleared once the frame is drawn -
167+
// GTK makes the context it needs current before using OpenGL but doesn't
168+
// check that this succeeded, and then uses whatever context is current. If
169+
// that is nothing it dereferences NULL and crashes.
170+
//
171+
// Leaving this context current gives GTK one to fall back on. It is created
172+
// on the same window and shares with the context GTK would have used itself,
173+
// so GTK can safely draw with it.
165174
if (self->render_context != nullptr) {
166175
gdk_gl_context_make_current(self->render_context);
167176
}
@@ -174,10 +183,6 @@ static gboolean fl_view_renderer_opengl_draw(GtkWidget* widget, cairo_t* cr) {
174183
height);
175184
}
176185

177-
if (self->render_context != nullptr) {
178-
gdk_gl_context_clear_current();
179-
}
180-
181186
g_mutex_unlock(&self->frame_mutex);
182187

183188
return result;

0 commit comments

Comments
 (0)