Subject: Re: bug#56967: 29.0.50; Frequent crashes under Wayland

From: Po Lu <[email-masked]>
Date: Fri, 05 Aug 2022 15:34:38 +0800

Eli Zaretskii <[email-masked]> writes:

>> From: Bennet Yee (余仕斌) <[email-masked]>
>> Date: Thu, 4 Aug 2022 11:12:44 -0700
>> 
>> FWIW I appeared to have just ran into this.  With emacs-gtk whenever I set mark and move down a line
>> (which would highlight the region) emacs would crash:
>> 
>> Backtrace:
>> emacs(+0x150ed5)[0x55cb9e339ed5]
>> emacs(+0x4aa38)[0x55cb9e233a38]
>> emacs(+0x4af22)[0x55cb9e233f22]
>> emacs(+0x14eefd)[0x55cb9e337efd]
>> emacs(+0x14ef7d)[0x55cb9e337f7d]
>> /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f068ca42520]
>> /lib/x86_64-linux-gnu/libX11.so.6(XVisualIDFromVisual+0x4)[0x7f068e1f5f24]
>> /lib/x86_64-linux-gnu/libgdk-3.so.0(gdk_x11_window_foreign_new_for_display+0x18e)[0x7f068e979a2e]
>> /lib/x86_64-linux-gnu/libgdk-3.so.0(+0x6b9f8)[0x7f068e9649f8]
>> /lib/x86_64-linux-gnu/libgdk-3.so.0(+0x6d191)[0x7f068e966191]
>> /lib/x86_64-linux-gnu/libgdk-3.so.0(+0x70d28)[0x7f068e969d28]
>> /lib/x86_64-linux-gnu/libgdk-3.so.0(gdk_display_get_event+0x89)[0x7f068e92fa99]
>> /lib/x86_64-linux-gnu/libgdk-3.so.0(+0x70f46)[0x7f068e969f46]
>> /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x26b)[0x7f068e37ed1b]
>> /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0xaa6f8)[0x7f068e3d36f8]
>> /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x33)[0x7f068e37c3c3]
>> /lib/x86_64-linux-gnu/libgtk-3.so.0(gtk_main_iteration+0x19)[0x7f068ec48d99]
>> emacs(+0x105073)[0x55cb9e2ee073]
>> emacs(+0x13d482)[0x55cb9e326482]
>> emacs(+0x13da75)[0x55cb9e326a75]
>> emacs(+0x1ba1b5)[0x55cb9e3a31b5]
>> emacs(+0xb55ec)[0x55cb9e29e5ec]
>> emacs(+0x7bac4)[0x55cb9e264ac4]
>> emacs(+0x8b9e8)[0x55cb9e2749e8]
>> emacs(+0x90783)[0x55cb9e279783]
>> emacs(+0xa5611)[0x55cb9e28e611]
>> emacs(+0xa8096)[0x55cb9e291096]
>> emacs(+0x1b30dc)[0x55cb9e39c0dc]
>> emacs(+0x94363)[0x55cb9e27d363]
>> emacs(+0x140ef3)[0x55cb9e329ef3]
>> emacs(+0x143bea)[0x55cb9e32cbea]
>> emacs(+0x14538c)[0x55cb9e32e38c]
>> emacs(+0x1b3047)[0x55cb9e39c047]
>> emacs(+0x136190)[0x55cb9e31f190]
>> emacs(+0x1b2f89)[0x55cb9e39bf89]
>> emacs(+0x13611e)[0x55cb9e31f11e]
>> emacs(+0x13b72a)[0x55cb9e32472a]
>> emacs(+0x13ba69)[0x55cb9e324a69]
>> emacs(+0x52aca)[0x55cb9e23baca]
>> /lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f068ca29d90]
>> /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f068ca29e40]
>> ...

Bennet Lee, do you have a clipboard manager installed on your system?
I'm going to guess changing the region caused ownership to be asserted
over the primary selection, in turn causing the clipboard manager to
send Emacs a selection request from an InputOnly window.  GDK then tried
to create a wrapper around that window, but crashed because the visual
of the InputOnly window could not be found in its own client-side record
of GDK visual objects.

This chain of events should only be possible on PGTK builds running on
X.  In that case, you should simply refrain from using PGTK on X.  This
problem and many others cause us to not support running such builds on
X.

If not, please see if the following change is sufficient to fix the
problem:

diff --git a/src/xterm.c b/src/xterm.c
index 4bbcfb0e59..5bc755b41f 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -17613,6 +17613,12 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 	    if (eventp->target == dpyinfo->Xatom_XmTRANSFER_FAILURE)
 	      x_dnd_action = None;
 	  }
+
+	/* Selection requests for the widget should never reach
+	   GDK.  */
+#ifdef USE_GTK
+	*finish = X_EVENT_DROP;
+#endif
       }
       break;