[Wayland] wxGTK crashes with GDK Error 71 on Aegisub (Issue #23961)

352 views
Skip to first unread message

witchymary

unread,
Oct 13, 2023, 4:13:54 PM10/13/23
to wx-...@googlegroups.com, Subscribed

To Reproduce:

  1. Download Aegisub from the Arch repos
  2. Launch it with GDK_BACKEND=wayland aegisub
  3. Go to Video -> Open Video... and open an mkv file
  4. See error

Description

Aegisub's video rederer crashes consistently on Wayland with the error: Gdk-Message: 16:09:57.355: Error 71 (Protocol error) dispatching to Wayland display. Downgrading to 3.2.2.1 fixes the issue. Here's the WAYLAND_DEBUG=1 log: https://pastebin.com/nVfkaN3h

Platform and version information

  • wxWidgets version you use: 3.2.3
  • wxWidgets port you use: wxGTK
  • OS: Arch Linux with Sway
  • GTK version: 3.24.38-1
  • Which GDK backend is used: Wayland


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23961@github.com>

VZ

unread,
Oct 13, 2023, 4:26:42 PM10/13/23
to wx-...@googlegroups.com, Subscribed

The relevant messages seem to be just those at the very end:

wl_di...@1.error(wl_subcompositor@43, 0, "Cannot reassign role wl_subsurface to wl_surface@40, role object still exists")
Gdk-Message: 16:24:27.856: Error 71 (Protocol error) dispatching to Wayland display.

but I don't really know where does this happen. Could you please run the program under gdb, break on _exit (which is what I think must be getting called by GTK in this situation) and use bt to check if it can provide us with more information?

I suspect this might be due to the changes of 1fb9618 (Handle map/unmap events on Wayland's wxGLCanvasEGL, 2023-08-25), see #22835, so cc'ing @joanbm.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23961/1762157381@github.com>

witchymary

unread,
Oct 13, 2023, 4:41:53 PM10/13/23
to wx-...@googlegroups.com, Subscribed

This is my first time using gdb, so apologies if I got anything wrong.

Gdk-Message: 17:40:42.028: Error 71 (Protocol error) dispatching to Wayland display.

Thread 1 "aegisub" hit Breakpoint 1.1, __GI__exit (status=status@entry=1)
    at ../sysdeps/unix/sysv/linux/_exit.c:27
27	{
(gdb) bt

#0  __GI__exit (status=status@entry=1) at ../sysdeps/unix/sysv/linux/_exit.c:27
#1  0x00007ffff336b868 in _gdk_wayland_display_queue_events (display=<optimized out>)
    at ../gtk/gdk/wayland/gdkeventsource.c:205
#2  _gdk_wayland_display_queue_events (display=<optimized out>)
    at ../gtk/gdk/wayland/gdkeventsource.c:193
#3  0x00007ffff3337fb9 in gdk_display_get_event (display=0x555555cd5e70)
    at ../gtk/gdk/gdkdisplay.c:442
#4  0x00007ffff3372838 in gdk_event_source_dispatch
    (base=<optimized out>, callback=<optimized out>, data=<optimized out>)
    at ../gtk/gdk/wayland/gdkeventsource.c:120
#5  0x00007ffff5b2bf19 in g_main_dispatch (context=0x555555ce3950)
    at ../glib/glib/gmain.c:3476
#6  0x00007ffff5b8a2b7 in g_main_context_dispatch_unlocked (context=0x555555ce3950)
    at ../glib/glib/gmain.c:4284
#7  g_main_context_iterate_unlocked.isra.0
    (context=0x555555ce3950, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/glib/gmain.c:4349
#8  0x00007ffff5b2cb47 in g_main_loop_run (loop=0x5555569e7570) at ../glib/glib/gmain.c:4551
#9  0x00007ffff35ecf6f in gtk_main () at ../gtk/gtk/gtkmain.c:1329
#10 0x00007ffff6fbeed6 in wxGUIEventLoop::DoRun() (this=0x555556864ff0)
    at /usr/src/debug/wxwidgets/wxWidgets-3.2.3/src/gtk/evtloop.cpp:61
#11 0x00007ffff74d8e12 in wxEventLoopBase::Run() (this=0x555556864ff0)
--Type <RET> for more, q to quit, c to continue without paging--<RET>
    at /usr/src/debug/wxwidgets/wxWidgets-3.2.3/src/common/evtloopcmn.cpp:87
#12 0x00007ffff74b4f28 in wxAppConsoleBase::MainLoop() (this=0x555555ccb600)
    at /usr/src/debug/wxwidgets/wxWidgets-3.2.3/src/common/appbase.cpp:381
#13 0x000055555586d7ac in AegisubApp::OnRun() (this=0x555555ccb600)
    at /usr/src/debug/aegisub/Aegisub/src/main.cpp:465
#14 0x00007ffff75163a0 in wxEntry(int&, wchar_t**)
    (argc=@0x7ffff7672624: 1, argv=<optimized out>)
    at /usr/src/debug/wxwidgets/wxWidgets-3.2.3/src/common/init.cpp:497
#15 0x00007ffff7516457 in wxEntry(int&, char**) (argc=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/wxwidgets/wxWidgets-3.2.3/src/common/init.cpp:509
#16 0x0000555555683377 in main(int, char**) (argc=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/aegisub/Aegisub/src/main.cpp:83```


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23961/1762172469@github.com>

Joan Bruguera

unread,
Oct 13, 2023, 5:05:45 PM10/13/23
to wx-...@googlegroups.com, Subscribed

I can reproduce the issue and indeed it is a regression between 3.2.2.1 and 3.2.3, checking now if it's related to the OpenGL changes or to something else...


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23961/1762221291@github.com>

Joan Bruguera

unread,
Oct 13, 2023, 6:59:19 PM10/13/23
to wx-...@googlegroups.com, Subscribed

Commit 1fb9618 (my recent changes for fixing showing/hiding wxGLCanvas on Wayland) appears to be the culprit indeed... I'll take a look tomorrow and try to figure out why.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23961/1762360216@github.com>

VZ

unread,
Oct 13, 2023, 7:01:22 PM10/13/23
to wx-...@googlegroups.com, Subscribed

Thanks a lot for looking at this!

Did you find a simpler way to reproduce the problem than using aegissub by chance? And, also, is it sway-specific or can be reproduced under mutter/GNOME?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23961/1762361336@github.com>

Joan Bruguera

unread,
Oct 13, 2023, 8:27:41 PM10/13/23
to wx-...@googlegroups.com, Subscribed

Did you find a simpler way to reproduce the problem than using aegissub by chance?

Yes, using the test case in #22580 (comment), but adding a canvas->Show(false); right after window->Show(true);. Then pressing the "Toggle" button after the window opens causes a crash / protocol error.

This is what Aegissub is doing (showing a window with a canvas, immediately hiding it, and then showing it again later).

And, also, is it sway-specific or can be reproduced under mutter/GNOME?

I can reproduce it on both Sway and GNOME-Shell.


From what I've figured out, the problem is a relatively dumb edge case:

In #23835 I ended up using the widget's map-event and unmap events (https://github.com/wxWidgets/wxWidgets/blob/v3.2.3/src/unix/glegl.cpp#L623), this was needed to handle various edge cases correctly.

map/unmap are the GTK events which are called synchronously from gtk_widget_show/gtk_widget_hide, and map-event/unmap-event are the GDK events which are called asynchronously on the event loop.

The order in which those events usually come is:

map
map-event --> We create the canvas subsurface
unmap --> We destroy it the canvas subsurface
unmap-event

However , if you show the canvas and immediately hide it before you pump from the event loop, , unmap comes before map-event:

map
unmap --> No-op
map-event --> We create the canvas subsurface, but never destroy it!
unmap-event

And later, when the canvas is actually shown, we try to create the canvas subsurface again and this causes the protocol error.

This seems to work as a fix, just detect this scenario where we receive the map-event after an unmap and ignore it:

diff --git a/src/unix/glegl.cpp b/src/unix/glegl.cpp
index 110a7b2f06..df1585d94e 100644
--- a/src/unix/glegl.cpp
+++ b/src/unix/glegl.cpp
@@ -583,6 +583,12 @@ wxGLCanvasEGL::~wxGLCanvasEGL()
 void wxGLCanvasEGL::CreateWaylandSubsurface()
 {
 #ifdef GDK_WINDOWING_WAYLAND
+    if (!gtk_widget_get_mapped(m_widget))
+    {
+        // The widget was hidden before we received the map-event, so ignore
+        return;
+    }
+
     GdkWindow *window = GTKGetDrawingWindow();
     struct wl_surface *surface = gdk_wayland_window_get_wl_surface(window);
 

I'll do some more testing tomorrow (and also see if I can come up with a more elegant fix) and submit a PR.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23961/1762419781@github.com>

Joan Bruguera

unread,
Oct 23, 2023, 7:29:08 PM10/23/23
to wx-...@googlegroups.com, Subscribed

I took a quick look at why even with the crash fix from #23968, on wxWidgets 3.2.3 moving the mouse inside the video display in Aegisub (which is supposed to render a crosshair centered at the mouse position) is very sluggish.

It turns out that Aegisub does not render the canvas on wxEVT_PAINT, but only on wxEVT_IDLE. But due to the changes from #23554, most attempts to draw on wxEVT_IDLE end up doing nothing (due to the flag m_readyToDraw being set to false at the time the idle event comes). This test application shows a big difference in fluidity between wxWidgets 3.2.2 and 3.2.3:

#include <wx/app.h>
#include <wx/glcanvas.h>
#include <wx/dcclient.h>
#include <wx/frame.h>
#include <wx/button.h>
#include <wx/sizer.h>

class MyWxApp : public wxApp
{
	double normX = 0.5;

public:
	bool OnInit() override {
		auto window = new wxFrame(nullptr, -1, wxT("Test"));
		auto canvas = new wxGLCanvas(window);
		auto context = new wxGLContext(canvas);
		canvas->Bind(wxEVT_IDLE, [this, canvas, context](wxIdleEvent &evt) {
			fprintf(stderr, "Canvas paint\n");
			context->SetCurrent(*canvas);

			glClearColor(normX, 0.0f, 0.0f, 1.0f);
			glClear(GL_COLOR_BUFFER_BIT);

			canvas->SwapBuffers();
		});

		canvas->Bind(wxEVT_MOTION, [this, canvas](wxMouseEvent &evt) {
			fprintf(stderr, "Mouse move\n");
			normX = (double)evt.GetPosition().x / canvas->GetSize().GetWidth();
		});

		window->Layout();
		window->Show(true);
		SetTopWindow(window);
		return true;
	}
};

IMPLEMENT_APP(MyWxApp)


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/23961/1776209016@github.com>

VZ

unread,
Oct 29, 2023, 7:44:07 PM10/29/23
to wx-...@googlegroups.com, Subscribed

Closed #23961 as completed via 133f773.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/23961/issue_event/10800995560@github.com>

Reply all
Reply to author
Forward
0 new messages