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 773814 - attempt to allocate widget with width -700975964 and height 400
attempt to allocate widget with width -700975964 and height 400
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-11-02 08:29 UTC by Alberto Garcia
Modified: 2017-05-08 22:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
box: Initialize size arrays to 0 (1.44 KB, patch)
2017-03-30 07:02 UTC, Timm Bäder
committed Details | Review

Description Alberto Garcia 2016-11-02 08:29:46 UTC
Hello,

I'm seeing a lot of these GTK+ warnings which come from what I believe
might be a bug in GtkBox:

   Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -700975964 and height 400

I debugged the code a bit and I think the problem is here (I turned
this into pseudocode for simplicity):

         ------------------------------------------------
gtk_box_size_allocate_no_center (GtkWidget           *widget,
                                 const GtkAllocation *allocation)
{
  GtkRequestedSize *sizes;
  sizes = g_newa (GtkRequestedSize, nvis_children);

  /* Retrieve desired size for visible children. */
  for (i = 0, children = private->children; children; children = children->next)
    {
      if (!_gtk_widget_get_visible (child->widget))
	continue;

      sizes[i] = gtk_widget_get_preferred_width_for_height(...);
    }

  /* Allocate child sizes. */
  for (i = 0, children = private->children; children; children = children->next)
    {
      if (!_gtk_widget_get_visible (child->widget))
	continue;

       child_allocation = sizes[i];

       gtk_widget_size_allocate_with_baseline (child->widget, &child_allocation, baseline);
    }
}
         ------------------------------------------------

So if a child is not visible we don't get its desired size (i.e. we
leave sizes[i] uninitialized) but later we don't allocate its size
either so that's not a problem.

However allocating the size of a visible child emits "size-allocate",
and its signal handler may end up showing a sibling that was
previously hidden, causing its child_allocation to be based on an
uninitialized sizes[i].

I found this with a GtkScrollbar that shows or hides itself after a
GtkAdjustment::changed signal from a sibling widget inside the same
container.
Comment 1 Benjamin Otte (Company) 2016-11-02 18:07:52 UTC
> However allocating the size of a visible child emits "size-allocate",
> and its signal handler may end up showing a sibling that was
> previously hidden

This must not happen. Any code that does this is broken. during size_allocate, visibility of widgets in the widget tree must not be changed.

We should probably initialize the sizes[i] = 0; for invisible widget as a workaround, so we'd not get this crazy warning. Also, uninitialized memory is bad.
Comment 2 Alberto Garcia 2016-11-02 22:05:14 UTC
(In reply to Benjamin Otte (Company) from comment #1)
> > However allocating the size of a visible child emits
> > "size-allocate", and its signal handler may end up showing a
> > sibling that was previously hidden

> This must not happen. Any code that does this is broken. during
> size_allocate, visibility of widgets in the widget tree must not be
> changed.

As I said in my code it was not exactly during size_allocate but upon
GtkAdjustment::changed. In the former case it looks intuitively like a
bad idea, in the latter not so much.

Thanks for the clarification anyway.
Comment 3 Timm Bäder 2017-03-30 07:02:58 UTC
Created attachment 348972 [details] [review]
box: Initialize size arrays to 0

We skip the later gtk_widget_get_preferred_foobar calls if the widget is
invisible, so we don't initialize some of the array entries. Luckily, 0
is both the width and height of an invisible widget.
Comment 4 Matthias Clasen 2017-04-03 20:13:16 UTC
Review of attachment 348972 [details] [review]:

sure
Comment 5 Matthias Clasen 2017-05-08 22:03:43 UTC
Attachment 348972 [details] pushed as f3f71ef - box: Initialize size arrays to 0