GNOME Bugzilla – Bug 754976
GtkFrame: Attempt to allocate size of width 1 (or a small number) fails
Last modified: 2015-10-23 14:41:36 UTC
Created attachment 311248 [details] Sample code Using GTK 3.17.8 (I also reproduced this with 3.10.8). Calling gtk_widget_size_allocate on a GtkFrame width of 1 (or a small number) fails with: Gtk-CRITICAL **: gtk_widget_get_preferred_height_for_width: assertion 'width >= 0' failed Gtk-CRITICAL **: gtk_widget_get_preferred_height_for_width: assertion 'width >= 0' failed Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -5 and height 148 This is because in gtk_frame_size_allocate, there is padding substracted from the allocation width: width = new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD; if the new_allocation.width is a small number , then this will result in a negative width See attached sample code that demonstrates the bug.
Created attachment 311249 [details] [review] Patch I made a patch that clamps the values so that the width is at least 1. According to the documentation of gtk_widget_size_allocate: "In this function, the allocation may be adjusted. It will be forced to a 1x1 minimum size" So I think this fix makes sense.
Widgets are not required to deal gracefully with being allocated a smaller size than they requested.
(In reply to Matthias Clasen from comment #2) > Widgets are not required to deal gracefully with being allocated a smaller > size than they requested. Doesn't that contradict a bit: "In this function, the allocation may be adjusted. It will be forced to a 1x1 minimum size" ? But if I understand correctly what you are saying, in terms of function calls: gtk_widget_size_allocate should never be called with values less than the minimum_size returned by gtk_widget_get_preferred_size? Is that correct? I'm trying to use this to set the minimum size before calling allocate but in my application (Eclipse) for some reason it comes back as 0x0. I'll investigate some more.
(In reply to Marc-Andre Laperle from comment #3) > But if I understand correctly what you are saying, in terms of function > calls: gtk_widget_size_allocate should never be called with values less than > the minimum_size returned by gtk_widget_get_preferred_size? Is that correct? > I'm trying to use this to set the minimum size before calling allocate but > in my application (Eclipse) for some reason it comes back as 0x0. I'll > investigate some more. OK so there were situations were the computation of the size ended up being less than minimum_size returned by gtk_widget_get_preferred_size. I made sure sure to clamp it before calling gtk_widget_size_allocate and that fixes the issue. I still find this part of the documentation unclear, in gtk_widget_size_allocate: "In this function, the allocation may be adjusted. It will be forced to a 1x1 minimum size"