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 438114 - ScrolledWindow is not fully initalized after init()
ScrolledWindow is not fully initalized after init()
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: GtkScrolledWindow
2.24.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2007-05-13 14:00 UTC by Patrik Fimml
Modified: 2018-05-02 14:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Testcase (1.37 KB, text/x-csrc)
2007-05-18 18:17 UTC, Patrik Fimml
  Details
Extra checks before accessing scrolled_window->[hv]scrollbar attributes (1.93 KB, patch)
2008-09-09 19:25 UTC, Björn Lindqvist
none Details | Review

Description Patrik Fimml 2007-05-13 14:00:37 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.
Comment 1 Owen Taylor 2007-05-13 15:58:33 UTC
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())



Comment 2 Patrik Fimml 2007-05-18 18:17:32 UTC
Created attachment 88409 [details]
Testcase

A test case. Compile with

gcc $(pkg-config --cflags --libs gtk+-2.0) -o test gnome-438114-test.c
Comment 3 Björn Lindqvist 2008-09-09 19:25:46 UTC
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.
Comment 4 GNOME Infrastructure Team 2018-05-02 14:29:13 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/281.