summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2023-03-04 18:11:36 +0100
committerBenjamin Otte <otte.benjamin@googlemail.com>2023-03-05 15:23:20 +0000
commitd3efd80b90413d86b899f66487a603c5e1a0bc28 (patch)
treefca4c0efe51494111b617c32cb9e4d137ec35e92
parenta899c0af6ebbac412d83cda046e6e3bf908d6de6 (diff)
downloadgtk+-d3efd80b90413d86b899f66487a603c5e1a0bc28.tar.gz
rendernodepaintable: Allow the node to be NULL
This can happen when creating paintables from GtkSnapshot when nothing was drawn.
-rw-r--r--gtk/gtkrendernodepaintable.c7
-rw-r--r--gtk/gtksnapshot.c9
2 files changed, 11 insertions, 5 deletions
diff --git a/gtk/gtkrendernodepaintable.c b/gtk/gtkrendernodepaintable.c
index bbe9cc5b13..87bb1ca19a 100644
--- a/gtk/gtkrendernodepaintable.c
+++ b/gtk/gtkrendernodepaintable.c
@@ -45,7 +45,8 @@ gtk_render_node_paintable_paintable_snapshot (GdkPaintable *paintable,
GtkRenderNodePaintable *self = GTK_RENDER_NODE_PAINTABLE (paintable);
if (self->bounds.size.width <= 0 ||
- self->bounds.size.height <= 0)
+ self->bounds.size.height <= 0 ||
+ self->node == NULL)
return;
gtk_snapshot_save (snapshot);
@@ -141,12 +142,12 @@ gtk_render_node_paintable_new (GskRenderNode *node,
{
GtkRenderNodePaintable *self;
- g_return_val_if_fail (GSK_IS_RENDER_NODE (node), NULL);
+ g_return_val_if_fail (node == NULL || GSK_IS_RENDER_NODE (node), NULL);
g_return_val_if_fail (bounds != NULL, NULL);
self = g_object_new (GTK_TYPE_RENDER_NODE_PAINTABLE, NULL);
- self->node = gsk_render_node_ref (node);
+ self->node = node ? gsk_render_node_ref (node) : NULL;
self->bounds = *bounds;
return GDK_PAINTABLE (self);
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index 1ebc641bea..bca57eaab2 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -1623,17 +1623,22 @@ gtk_snapshot_to_paintable (GtkSnapshot *snapshot,
{
graphene_size_init_from_size (&bounds.size, size);
}
- else
+ else if (node)
{
gsk_render_node_get_bounds (node, &bounds);
bounds.size.width += bounds.origin.x;
bounds.size.height += bounds.origin.y;
}
+ else
+ {
+ bounds.size.width = 0;
+ bounds.size.height = 0;
+ }
bounds.origin.x = 0;
bounds.origin.y = 0;
paintable = gtk_render_node_paintable_new (node, &bounds);
- gsk_render_node_unref (node);
+ g_clear_pointer (&node, gsk_render_node_unref);
return paintable;
}