After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 753185 - gdk_device_get_source: assertion 'GDK_IS_DEVICE (device)' failed
gdk_device_get_source: assertion 'GDK_IS_DEVICE (device)' failed
Product: gtk+
Classification: Platform
Component: Backend: Wayland
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
Depends on:
Reported: 2015-08-03 15:31 UTC by Carlos Garnacho
Modified: 2015-08-19 20:15 UTC
See Also:
GNOME target: ---
GNOME version: ---

gdkevent: Hold refs to device/source_device (2.20 KB, patch)
2015-08-03 15:32 UTC, Carlos Garnacho
committed Details | Review

Description Carlos Garnacho 2015-08-03 15:31:38 UTC
On wayland we may destroy the "master" pointer/keyboard devices right when we receive a wl_seat.capability event, despite the events that might be queued for these at that time.

This is visible on tty switch, mutter will first send the key release for the ctrl/alt modifiers, gtk+ queues these events, but destroys the devices immediately after. The focused window will then spawn several:

Gdk-CRITICAL **: gdk_device_get_source: assertion 'GDK_IS_DEVICE (device)' failed

Triggered when the GtkGesture generic event handling code receives the event.

This didn't use to trigger on X11 because VCP/VCK are not removed, only the slave devices are, although if we had performed any checks on the source devices, we would surely have received warnings as well.

I'm attaching a patch that makes the private device/source_device event fields refcounted, so the events at least contain valid GdkDevices when processed.
Comment 1 Carlos Garnacho 2015-08-03 15:32:03 UTC
Created attachment 308683 [details] [review]
gdkevent: Hold refs to device/source_device

The extra reference will be held from GdkEventPrivate data, so there's
a common place to all events. Without this, events queued after devices/
capabilities disappear (eg. on TTY switch) might hold invalid pointers.
Windowing level operations on those devices (queries, grabs...) are
expected to fail at that time, but we should hold meaningful data for
the regular event handling paths.
Comment 2 Matthias Clasen 2015-08-03 17:42:05 UTC
Not holding on to pointers that point to finalized objects seems good, of course. But can we recognize the 'deceased' status of the devices somehow ? Is there a GdkDevice api for that ?
Comment 3 Matthias Clasen 2015-08-04 16:29:27 UTC
Review of attachment 308683 [details] [review]:

setting review status according to the previous comment
Comment 4 Carlos Garnacho 2015-08-05 09:54:19 UTC
(In reply to Matthias Clasen from comment #2)
> Not holding on to pointers that point to finalized objects seems good, of
> course. But can we recognize the 'deceased' status of the devices somehow ?
> Is there a GdkDevice api for that ?

Hmm, right, there's actually nothing to let users know. On X11 I'd count on BadDevice to be received on any device operation, and GTK+ to bail out of there, on wayland this post-removal behavior is a bit more naive though.

What AFAIR we would be emitting is grab broken events if there is one at the time of the removal, and I wouldn't expect that button/key releases will trigger grabs or device state queries too often, We should stress test device operations around removals nonetheless.
Comment 5 Carlos Garnacho 2015-08-19 20:15:49 UTC
Attachment 308683 [details] pushed as 25557c1 - gdkevent: Hold refs to device/source_device