Subject: Re: bug#76239: crash with "gdk_device_get_name: assertion 'GDK_IS_DEVICE (device)' failed" error on kde 6.3, fedora 41

From: Arsen Arsenović <[email-masked]>
Date: Sat, 15 Feb 2025 19:53:58 +0100

Hi Pip,

Pip Cet <[email-masked]> writes:

> "Po Lu" <[email-masked]> writes:
>
>> Pip Cet <[email-masked]> writes:
>>
>>> "Eli Zaretskii" <[email-masked]> writes:
>>>
>>>>> From: समीर सिंह Sameer Singh
>>>>>  <[email-masked]>
>>>>> Date: Thu, 13 Feb 2025 02:21:00 +0530
>>>>>
>>>>> after upgrading to kde 6.3 on my fedora 41 machine, emacs fails to
>>>>> start with the following error
>>>>> ---------------------------------------------------------------------------------------------------------------
>>>>> (emacs:84925): Gdk-CRITICAL **: 02:00:31.252: gdk_device_get_name:
>>>>> assertion 'GDK_IS_DEVICE (device)' failed
>>>>
>>>> Po Lu, any comments or suggestions?
>>>
>>> This bug probably became more apparent with the recent change to use
>>> doprnt.c for make_formatted_string, which crashes when passed a NULL
>>> string rather than printing "(nil)" as glibc does.  We might want to
>>> change that, though the underlying bug needs to be fixed, too.
>>>
>>>>> #4  0x0000000000748c4b in pgtk_enumerate_devices (dpyinfo=0xb3a100,
>>>>> initial_p=true) at pgtkterm.c:188
>>>>>         rec = 0xc8a6f0
>>>>>         all_seats = 0xba6c30 = {0xa57ec0}
>>>>>         devices_on_seat = 0xba6c50 = {0x0, 0xa41920, 0x9e9800,
>>>>> 0xb05da0, 0xa8b210}
>>>
>>> If this is to be believed, the return value of gdk_seat_get_slaves
>>> (renamed to gdk_seat_get_devices in 2020, it seems) contained a NULL
>>> pointer?
>>>
>>> Looking at gdkseat-wayland.c, it seems most likely to be
>>> 9f4320a4acbc104a8fce09c0a948d0f99e0feb98, which leaves a tablet pad's
>>> ->device pointer as NULL until it "enters" a surface:
>>>
>>> https://github.com/GNOME/gtk/commit/9f4320a4acbc104a8fce09c0a948d0f99e0feb98
>>>
>>> Do you have something that would count as a tablet pad?
>>>
>>> Pip
>>
>> Thanks.  This is certainly a bug in GDK, which I suggest reporting to
>> their developers, and for the present I will install a workaround in
>> emacs-30 tomorrow.
>
> https://gitlab.gnome.org/GNOME/gtk/-/issues/7337 appears to have been
> opened by Arsen Arsenovic a while ago.  No response so far, but it
> describes the problem accurately.

It's been just about a day, not too long, and it's weekend ;P

> Thanks, Arsen!

No problem!

> (I would have linked the issue but gitlab.gnome.org is not letting me
> create an account, so I won't).

Try https://register.gitlab.gnome.org/ - it worked for me.

I've a workaround locally.  I didn't want to post it because it's an
ugly hack and I expected to submit a fix upstream at some point soon
(plus, KDE 6.3 just came out so I figured few people would hit this):

~$ cat /etc/portage/patches/app-editors/emacs/workaround-gtk-bug.patch 
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index d47b1da7262..0ca9ed1aa7c 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -182,6 +182,9 @@ pgtk_enumerate_devices (struct pgtk_display_info *dpyinfo,
 
       for (t1 = devices_on_seat; t1; t1 = t1->next)
 	{
+	 if (!t1->data)
+	   continue;
+
 	 rec = xmalloc (sizeof *rec);
 	 rec->seat = g_object_ref (seat);
 	 rec->device = GDK_DEVICE (t1->data);

The above should be okay (with an explanatory comment added, of course),
as ISTM that all usages of this list could handle a device being
missing.
-- 
Arsen Arsenović