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 770003 - "How does the code know the size to allocate?" from gtk_window_check_resize() under gtk_container_idle_sizer()
"How does the code know the size to allocate?" from gtk_window_check_resize()...
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: Other
3.20.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-08-16 16:55 UTC by Milan Crha
Modified: 2018-05-02 17:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test case (1.93 KB, text/plain)
2017-03-15 18:45 UTC, Peter Bloomfield
Details
simpler test case (1.44 KB, text/x-csrc)
2017-03-15 22:20 UTC, Peter Bloomfield
Details
Gdb stack trace (12.10 KB, text/plain)
2017-05-14 16:25 UTC, Peter Bloomfield
Details

Description Milan Crha 2016-08-16 16:55:15 UTC
This is with gtk3-3.20.8-1.fc24. Running locally built test-html-editor from evolution-3.21.90/e-util (which is a noinst_PROGRAMS) shows a runtime warning:

(test-html-editor:25481): Gtk-WARNING **: Allocating size to GtkWindow 0x108d450 without calling gtk_widget_get_preferred_width/height(). How does the code know the size to allocate?

With the below backtrace. Maybe there is something what the editor does wrong, but I do not know how to debug this further, thus any help will be appreciated. Note that the GtkWindow's parent is NULL.

(gdb) bt
  • #0 g_logv
  • #1 g_log
  • #2 gtk_widget_size_allocate_with_baseline
    at gtkwidget.c line 5997
  • #3 gtk_widget_size_allocate
    at gtkwidget.c line 6217
  • #4 gtk_window_check_resize
    at gtkwindow.c line 9875
  • #5 gtk_window_check_resize
    at gtkwindow.c line 8275
  • #6 _g_closure_invoke_va
  • #7 g_signal_emit_valist
  • #8 g_signal_emit
  • #9 gtk_container_idle_sizer
    at gtkcontainer.c line 2064
  • #10 _g_closure_invoke_va
  • #11 g_signal_emit_valist
  • #12 g_signal_emit
  • #13 _gdk_frame_clock_emit_layout
    at gdkframeclock.c line 634
  • #14 gdk_frame_clock_paint_idle
    at gdkframeclockidle.c line 408
  • #15 gdk_threads_dispatch
    at gdk.c line 720
  • #16 g_timeout_dispatch
  • #17 g_main_context_dispatch
  • #18 g_main_context_iterate.isra
  • #19 g_main_loop_run
  • #20 gtk_main
    at gtkmain.c line 1269
  • #21 main
    at test-html-editor.c line 580

Comment 1 Peter Bloomfield 2017-03-15 18:45:32 UTC
Created attachment 348030 [details]
test case

This test case yields exactly the same stack trace.
Comment 2 Peter Bloomfield 2017-03-15 18:53:35 UTC
The test case is a tree-view in a scrolled-window in the content-area of a dialog. The dialog is transient for a top-level window, which is there only because not having one "is discouraged".

The "Allocating size" warning is not issued when the dialog is shown, but each time when the tree-view in the scrolled window is expanded.
Comment 3 Peter Bloomfield 2017-03-15 22:20:00 UTC
Created attachment 348042 [details]
simpler test case

Turns out the dialog is not needed: adding the scrolled-window to a top-level window is enough to trigger the warnings each time the tree-view is expanded.
Comment 4 Vendula Poncova 2017-03-27 08:46:17 UTC
It looks like we ran into the same problem in our application.
Comment 5 Alberto Garcia 2017-03-29 22:40:02 UTC
This looks similar to bug 773814
Comment 6 Peter Bloomfield 2017-05-12 23:00:30 UTC
Here's all I can figure out:
• The warning is issued by gtk_widget_size_allocate_with_baseline() when gtk_widget_get_resize_needed() is TRUE; that's a macro that just returns widget->priv->resize_needed.
• widget->priv->resize_needed is set only in gtk_widget_queue_resize_on_widget(), 
which is exported by gtkwidget.c but used only internally, by gtk_widget_queue_resize_internal().
• gtk_widget_queue_resize_internal() is called by gtk_widget_queue_resize_no_redraw() and by gtk_widget_queue_resize().

I ran the test case, and set breakpoints on both functions when the window was showing but before clicking the descender. In the dozen or so traps after clicking it and before the warning was issued, none was for the GtkWindow named in the warning. So it looks as though priv->resize_needed is not getting cleared after the initial drawing of the window.
Comment 7 Peter Bloomfield 2017-05-13 00:06:00 UTC
AFAICT priv->resize_needed is cleared only by gtk_widget_ensure_resize().
Another debugging run shows that gtk_widget_ensure_resize() is *always* called at least once after gtk_widget_queue_resize() and before gtk_widget_size_allocate_with_baseline(). So it's unclear how it gets set to trigger the warning.
Comment 8 Peter Bloomfield 2017-05-14 16:25:54 UTC
Created attachment 351836 [details]
Gdb stack trace
Comment 9 Peter Bloomfield 2017-05-14 16:35:10 UTC
The stack trace resulted from setting a breakpoint on gtk_widget_queue_resize_on_widget, which is called on the GtkWindow immediately before the call to gtk_widget_size_allocate_with_baseline that triggers the warning.

Frame #24 is a call to gtk_widget_get_preferred_width, and ultimately at frame #1 gtk_widget_queue_resize_internal is called on an embedded widget, and then recurses up all the way to the toplevel window, setting resize_needed on all the widgets.

The only obvious fix is a hack: call gtk_widget_ensure_resize on the window immediately after gtk_widget_get_preferred_width returns in gtk_window_get_preferred_width. The real solution would be to avoid setting resize_needed inside a call to gtk_widget_get_preferred_width, but that appears to need more intrusive changes.
Comment 10 Milan Crha 2017-05-15 07:53:47 UTC
(In reply to Peter Bloomfield from comment #9)
> The only obvious fix is a hack: call gtk_widget_ensure_resize on the window
> immediately after gtk_widget_get_preferred_width returns in
> gtk_window_get_preferred_width. The real solution would be to avoid setting
> resize_needed inside a call to gtk_widget_get_preferred_width, but that
> appears to need more intrusive changes.

Or the warning is simply useless, bothers users and developers, the most because it's a false-positive in valid cases. I saw it also with WebKitGTK+ (WebKit1) with embedded GtkWidget-s. The code knows the size, because the HTML code defining the embedded GtkWidget has appropriate values (width/hight) defined. That's something what gtk+ itself cannot cover by this runtime warning. Nonetheless, the above backtrace (this bug) is about gtk+ code only.
Comment 11 GNOME Infrastructure Team 2018-05-02 17:25:28 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/658.