From a483fb2d969c2f2869779b32d27f5969a9194a1d Mon Sep 17 00:00:00 2001 From: tszymanski Date: Tue, 1 Aug 2023 22:17:54 -0700 Subject: [PATCH 1/2] gtkgridview: Fix crash on scroll to 0 sized tile No longer crashes with my listview_clocks demo or in real scrolling in my application. "GtkGridView failed to scroll to given position. Ignoring..." warnings are printed when it would have crashed. Sometimes the scroll jumps incorrectly when it doesn't crash, but that's a separate bug but is probably related to whatever is causing this crash. Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5945, at least in terms of the immediate crash. --- gtk/gtkgridview.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index dd36309844..82ece4e8f6 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -431,6 +431,11 @@ gtk_grid_view_get_position_from_allocation (GtkListBase *base, { guint rows_in_tile = tile->n_items / self->n_columns; guint row_height = (tile->area.height + yspacing) / rows_in_tile - yspacing; + + /* tile has no computed area */ + if (row_height + yspacing == 0) + return FALSE; + guint row_index = MIN (tile->area.height - 1, y - tile->area.y) / (row_height + yspacing); pos += self->n_columns * row_index; From 70a9d08e21c03888b271dda8dac29e9d8416bf1b Mon Sep 17 00:00:00 2001 From: tszymanski Date: Sun, 6 Aug 2023 10:26:32 -0700 Subject: [PATCH 2/2] gtkgridview: return empty area for empty tiles during scroll --- gtk/gtkgridview.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index 82ece4e8f6..e3983649f6 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -411,7 +411,7 @@ gtk_grid_view_get_position_from_allocation (GtkListBase *base, } pos = gtk_list_tile_get_position (self->item_manager, tile); - if (tile->n_items > 1) + if (tile->n_items > 1 && tile->area.width > 0 && tile->area.height > 0) { int xspacing, yspacing; @@ -431,11 +431,6 @@ gtk_grid_view_get_position_from_allocation (GtkListBase *base, { guint rows_in_tile = tile->n_items / self->n_columns; guint row_height = (tile->area.height + yspacing) / rows_in_tile - yspacing; - - /* tile has no computed area */ - if (row_height + yspacing == 0) - return FALSE; - guint row_index = MIN (tile->area.height - 1, y - tile->area.y) / (row_height + yspacing); pos += self->n_columns * row_index;