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 754976 - GtkFrame: Attempt to allocate size of width 1 (or a small number) fails
GtkFrame: Attempt to allocate size of width 1 (or a small number) fails
Status: RESOLVED WONTFIX
Product: gtk+
Classification: Platform
Component: Widget: Other
3.17.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2015-09-14 02:27 UTC by Marc-Andre Laperle
Modified: 2015-10-23 14:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Sample code (956 bytes, text/plain)
2015-09-14 02:27 UTC, Marc-Andre Laperle
  Details
Patch (1.18 KB, patch)
2015-09-14 02:30 UTC, Marc-Andre Laperle
none Details | Review

Description Marc-Andre Laperle 2015-09-14 02:27: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.
Comment 1 Marc-Andre Laperle 2015-09-14 02:30:59 UTC
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.
Comment 2 Matthias Clasen 2015-09-16 14:23:23 UTC
Widgets are not required to deal gracefully with being allocated a smaller size than they requested.
Comment 3 Marc-Andre Laperle 2015-09-16 19:07:03 UTC
(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.
Comment 4 Marc-Andre Laperle 2015-10-23 14:41:36 UTC
(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"