GNOME Bugzilla – Bug 438114
ScrolledWindow is not fully initalized after init()
Last modified: 2018-05-02 14:29:13 UTC
When creating a scrolled window by other means than gtk_scrolled_window_new(), e.g. from a child widget, it is not fully initialized after its init function. The scrollbar members as well as the adjustments are NULL, whereas various functions rely on them being objects. Adding a widget from a child class' init function, for example, produces Gtk-CRITICAL **: gtk_range_get_adjustment: assertion `GTK_IS_RANGE (range)' failed warnings. Workaround: Set the adjustments to anything (even NULL does the trick), because gtk_scrolled_window_set_[hv]adjustment then will take care of creating adjustments and scrollbars, e.g. g_object_set(object, "hadjustment", NULL, "vadjustment", NULL, NULL); or the appropriate C functions Proposed solution: init() should either create adjustments or scrollbars, or all functions using them should check them for NULL.
A) A test case here would be useful B) Creating them in init() is a bad idea, because it cause a situation where the adjustments are created and then immediately destroyed if someone passes non-null-values to gtk_hscrollbar_new() What I'd suggest is adding a constructor() function that creates the scrollbars if not already created, then sets the adjustments on the child if one has been previously added. (Plus a check for null-scrollbars in add())
Created attachment 88409 [details] Testcase A test case. Compile with gcc $(pkg-config --cflags --libs gtk+-2.0) -o test gnome-438114-test.c
Created attachment 118378 [details] [review] Extra checks before accessing scrolled_window->[hv]scrollbar attributes This patch adds more checks and fixes the warnings by calling the safe gtk_scrolled_window_get_[hv]adjustment() functions. I still think it would be smarter to initialize the scrollbars in gtk_scrolled_window_init(), instead of adding millions of extra checks all over the place.
-- 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/281.