[gtk/fallback-menu-critical] popovermenu: Avoid a critical




commit f8a303b0e53293f8f077a8bdf72b1d9389761b5d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Aug 2 13:09:00 2020 -0400

    popovermenu: Avoid a critical
    
    While we guarantee that the widget that a controller
    is attached to stays around while it is handling an event,
    the same is not true for the root that the widget belongs
    to. In corner cases (such as clicking "Close" in the
    fallback window menu), it may already be gone.
    Avoid a critical in that case.
    
    Fixes: #2998

 gtk/gtkpopovermenu.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 2108f15535..707429c730 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -228,7 +228,14 @@ static void
 focus_out (GtkEventController   *controller,
            GtkPopoverMenu       *menu)
 {
-  GtkWidget *new_focus = gtk_root_get_focus (gtk_widget_get_root (GTK_WIDGET (menu)));
+  GtkRoot *root;
+  GtkWidget *new_focus;
+
+  root = gtk_widget_get_root (GTK_WIDGET (menu));
+  if (!root)
+    return;
+
+  new_focus = gtk_root_get_focus (root);
 
   if (!gtk_event_controller_focus_contains_focus (GTK_EVENT_CONTROLLER_FOCUS (controller)) &&
       new_focus != NULL)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]