Skip to content

Commit 238dd2a

Browse files
joanbmvadz
authored andcommitted
Ignore spurious map-events on Wayland's wxGLCanvasEGL
In the recent changes for handling map/unmap events on Wayland's wxGLCanvasEGL, we use the following GTK widget signals: * The "map-event" signal to create the canvas's subsurface. The earlier "map" signal can not be used, as the associated toplevel window's Wayland surface may not yet exist by the time we receive it. * The "unmap" signal to destroy the canvas's subsurface. Using the later "unmap-event" signal is problematic, due to other resources we build upon being already destroyed by then. Usually, the "map-event" signal comes before "unmap" and resources are created and destroyed appropriately. However, there's an edge case: If a canvas is shown and then immediately hidden (before wxWidgets can pump from the event loop), "unmap" will come before "map-event". This happens because signals like "map" and "unmap" are delivered immediately (when calling e.g. `gtk_widget_hide`), while signals like "map-event" and "unmap-event" are delivered later on the event loop. For the same reason, showing a canvas, then immediately hiding it, then immediately showing it again, will cause two "map-event"s to get delivered enqueued without a "unmap" in between. This condition can be hit quite easily when setting up a complex UIs, and in particular it is triggered by Aegisub during startup, leading to a crash (Wayland protocol error) when opening a video later, or when specifying a video directly on the startup command line. To avoid this breaking our resource management, add some checks to detect those "map-event"s we shouldn't handle - either the ones that happen after "unmap", or the duplicate ones without an "unmap" in between. See wxWidgets#23961, wxWidgets#23968. (cherry picked from commit 133f773)
1 parent 3d235b8 commit 238dd2a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/unix/glegl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,21 @@ wxGLCanvasEGL::~wxGLCanvasEGL()
641641
void wxGLCanvasEGL::CreateWaylandSubsurface()
642642
{
643643
#ifdef GDK_WINDOWING_WAYLAND
644+
// It's possible that we get in here unnecessarily in two ways:
645+
// (1) If the canvas widget is shown, and then immediately hidden, we will
646+
// still receive a map-event signal, but by that point, the subsurface
647+
// does not need to be created anymore as the canvas is hidden
648+
// (2) If the canvas widget is shown, and then immediately hidden, and then
649+
// immediately shown again, we will receive two map-event signals.
650+
// By the second time we get it, the subsurface will already be created
651+
// Not ignoring either of the two scenarios will likely cause the subsurface
652+
// to be created twice, leading to a crash due to a Wayland protocol error
653+
// See https://github.com/wxWidgets/wxWidgets/issues/23961
654+
if ( !gtk_widget_get_mapped(m_widget) || m_wlSubsurface )
655+
{
656+
return;
657+
}
658+
644659
GdkWindow *window = GTKGetDrawingWindow();
645660
struct wl_surface *surface = gdk_wayland_window_get_wl_surface(window);
646661

0 commit comments

Comments
 (0)