# Reproducible crash when using gtk2 2.18.0

**URL:** <https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065>\
**Category:** Ruby-Gnome 2\
**Created:** [September 24, 2009, 9:47am UTC](https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065 "2009-09-24T09:47:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [September 24, 2009, 9:47am UTC](https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065/1 "2009-09-24T09:47:02Z")

</div>

Hi,

The following program:

-=-=—=-=—=-=—=-=–  
require ‘gtk2’  
Gtk::Window.new.show\_all.signal\_connect(“delete-event”) { |e,w|  
w.window.cursor = Gdk::Cursor.new(Gdk::Cursor::WATCH) }  
Gtk.main  
-=-=—=-=—=-=—=-=–

crashes when trying to close the window, when used with gtk 2.18.0  
runtime (or a late 2.17.x), but not with gtk 2.16.1 or 2.14.3 (glib  
being 2.22.0). rg2 versions tried were 0.19.0, 0.19.1, and 019.2; we  
also tried to recompile rg2 against gtk 2.18.0, all that make no  
differences. export GDK\_NATIVE\_WINDOWS=1 also makes no difference.  
Valgrind[1] says the crash is related to something in gdk/X:

==1833== Invalid read of size 4  
==1833== at 0x4F091DD: XAddExtension (in /usr/lib/libX11.so.6.2.0)  
==1833== by 0x5CDBDC6: \_XcursorGetDisplayInfo (in  
/usr/lib/libXcursor.so.1.0.2)  
==1833== by 0x5CDC48A: XcursorGetDefaultSize (in  
/usr/lib/libXcursor.so.1.0.2)  
==1833== by 0x5CDEACD: XcursorLibraryLoadCursor (in  
/usr/lib/libXcursor.so.1.0.2)  
==1833== by 0x5CDEBAA: XcursorShapeLoadCursor (in  
/usr/lib/libXcursor.so.1.0.2)  
==1833== by 0x5B98111: \_gdk\_x11\_cursor\_update\_theme  
(gdkcursor-x11.c:587)  
==1833== by 0x5BBB3DC: gdk\_window\_x11\_set\_cursor  
(gdkwindow-x11.c:2738)  
==1833== by 0x5B846B5: update\_cursor (gdkwindow.c:8735)  
==1833== by 0x5B8722F: gdk\_window\_set\_cursor (gdkwindow.c:7666)  
==1833== by 0x478A84F: g\_object\_set\_property (in  
/usr/lib/libgobject-2.0.so.0.2200.0)  
==1833== by 0x4750734: ??? (in  
/usr/lib/ruby/site\_ruby/1.8/i586-linux/glib2.so)  
==1833== by 0x4062CF1: call\_cfunc (eval.c:5771)  
==1833== Address 0x74050453 is not stack’d, malloc’d or (recently)  
free’d

(libX11R6 is 1.2.1 and libXcursor is 1.1.9 but downgrading these makes  
no difference)

_but_ the equivalent program in C doesn’t crash:

-=-=—=-=—=-=—=-=–  
#include \<gtk/gtk.h\>

static void setcursor( GtkWidget \*widget, gpointer data ) {  
GdkCursor \*cursor = gdk\_cursor\_new(GDK\_WATCH);  
GdkWindow \*win = widget-\>window;  
gdk\_window\_set\_cursor(win, cursor);  
}

int main( int argc, char \*argv[] ) {  
GtkWidget \*window;  
gtk\_init (&argc, &argv);  
window = gtk\_window\_new (GTK\_WINDOW\_TOPLEVEL);  
gtk\_widget\_show\_all(window);  
g\_signal\_connect (G\_OBJECT (window), “delete\_event”, G\_CALLBACK  
(setcursor), NULL);  
gtk\_main ();  
return 0;  
}  
-=-=—=-=—=-=—=-=–

I also tried to rewrite the setcursor function to use  
g\_object\_set\_property, but it makes no difference (it still doesn’t  
crash in C):

-=-=—=-=—=-=—=-=–  
GValue item = { 0, };  
g\_value\_init (&item, G\_TYPE\_POINTER);  
GdkCursor \*cursor = gdk\_cursor\_new(GDK\_WATCH);  
GdkWindow \*win = widget-\>window;  
g\_value\_set\_pointer(&item, cursor);  
g\_object\_set\_property(G\_OBJECT(win), “cursor”, &item);  
-=-=—=-=—=-=—=-=–

(though I am not sure how to choose the G\_TYPE in such a case)

I guess there is something specific with how rg2 “uses” gtk but it’s  
difficult to say from that point on… It would be useful to have a  
means to automatically generate the exact equivalent of C calls to gtk  
from a rg2-based program (I know, this is idealistic).

Anyway, any idea maybe, someone?

[1] valgrind --tool=memcheck --suppressions=/tmp/valgrind-ruby.supp[2]  
ruby test.rb

[2]  
[http://cvs.m17n.org/viewcvs/ruby/valgrind-ruby/valgrind-ruby.supp?revision=1.3&view=markup](http://cvs.m17n.org/viewcvs/ruby/valgrind-ruby/valgrind-ruby.supp?revision=1.3&view=markup)  
(don’t forget to have debugging symbols available for  
suppressions to work properly)

–  
Guillaume C. - [http://zarb.org/~gc/](http://zarb.org/~gc/)

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [September 24, 2009, 12:25pm UTC](https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065/2 "2009-09-24T12:25:06Z")

</div>

Guillaume C. wrote:

> Hi,
> 
> The following program:
> 
> -=-=—=-=—=-=—=-=–  
> require ‘gtk2’  
> Gtk::Window.new.show\_all.signal\_connect(“delete-event”) { |e,w|  
> w.window.cursor = Gdk::Cursor.new(Gdk::Cursor::WATCH) }  
> Gtk.main  
> -=-=—=-=—=-=—=-=–

This is what I get with ruby 1.8.6p383, rg2-0.19.2, each time I click on  
close button.

(eval): line 2  
Gdk-CRITICAL \*\*:gdk\_cursor\_ref: assertion `cursor-\>ref\_count \> 0’  
failed

but no crash.

# LANGUAGE=C aptitude show libgtk2.0-dev

Package: libgtk2.0-dev  
New: yes  
State: installed  
Automatically installed: no  
Version: 2.18.0-1

If it can help you.

Simon

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [September 24, 2009, 12:26pm UTC](https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065/3 "2009-09-24T12:26:36Z")

</div>

Simon A. wrote:

> This is what I get with ruby 1.8.6p383, rg2-0.19.2, each time I click on  
> close button.

Forgot to say, both built from sources after aptitude updates.

simon

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [September 27, 2009, 6:16am UTC](https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065/4 "2009-09-27T06:16:28Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] reproducible crash when using gtk2 2.18.0” on  
Thu, 24 Sep 2009 09:46:22 +0200,  
Guillaume C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> runtime (or a late 2.17.x), but not with gtk 2.16.1 or 2.14.3 (glib  
> being 2.22.0).

I’ve fixed it in trunk.  
You doesn’t need to use set\_cursor instead of cursor=.

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [September 24, 2009, 12:53pm UTC](https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065/5 "2009-09-24T12:53:35Z")

</div>

Guillaume C. wrote:

> -=-=—=-=—=-=—=-=–  
> require ‘gtk2’  
> Gtk::Window.new.show\_all.signal\_connect(“delete-event”) { |e,w|  
> w.window.cursor = Gdk::Cursor.new(Gdk::Cursor::WATCH) }  
> Gtk.main  
> -=-=—=-=—=-=—=-=–

Btw, with set\_cursor, it works as expected, here.  
w.window.set\_cursor Gdk::Cursor.new(Gdk::Cursor::WATCH)

I couldn’t find where cursor= is defined in my little research.

I also noticed, I can interchange w and e, and it still works 😕  
Either |e,w| or |w,e| works the same.  
Someone knows why ?

regards

Simon

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [September 27, 2009, 10:00am UTC](https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065/6 "2009-09-27T10:00:03Z")

</div>

> > crashes when trying to close the window, when used with gtk 2.18.0  
> > runtime (or a late 2.17.x), but not with gtk 2.16.1 or 2.14.3 (glib  
> > being 2.22.0).
> 
> I’ve fixed it in trunk.

Thanks Kou. That said, a specific workaround in rg2 potentially means  
more crashes in corner cases. So I’ve investigated a bit more and I  
think the problem was in rbgobj\_valuetypes.c:

gpointer  
rbgobj\_ptr2cptr(ptr)  
VALUE ptr;  
{  
#ifdef RBGOBJ\_USE\_DLPTR  
return rb\_dlptr2cptr(ptr);  
#else  
gpointer dest;  
if (rb\_obj\_is\_kind\_of(ptr, GTYPE2CLASS(G\_TYPE\_POINTER))){  
Data\_Get\_Struct(ptr, void, dest);  
} else if (rb\_obj\_is\_kind\_of(ptr, rb\_cObject)){

```
    dest = (gpointer)ptr;
} else{
    rb_raise(rb_eTypeError, "not a pointer object");
}
return dest;

```

#endif  
}

–  
Guillaume C. - [NVC Communication Obstacles Game](http://zarb.org/~gc/)

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [September 29, 2009, 2:11pm UTC](https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065/7 "2009-09-29T14:11:19Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] reproducible crash when using gtk2 2.18.0”  
on Sun, 27 Sep 2009 10:02:57 +0200,  
Guillaume C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Thanks Kou. That said, a specific workaround in rg2 potentially means  
> > ,A ,A gpointer dest;  
> > }
> 
> So I guess the problem is the “gpointer” type of cursor property in  
> GdkWindow is too imprecise for rg2, or at least for rg2’s  
> implementation of properties use. Mistake or not, I don’t know, but  
> I’ve filed in gnome bugzilla:
> 
> [Bug 596494 – New property "cursor" in 2.18's GdkWindow with wrong type?](https://bugzilla.gnome.org/show_bug.cgi?id=596494)

Thanks! The bug item makes sense!

–  
kou

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [September 27, 2009, 10:03am UTC](https://www.ruby-forum.com/t/reproducible-crash-when-using-gtk2-2-18-0/176065/8 "2009-09-27T10:03:34Z")

</div>

Grmbl, too fast posting!

On Sun, Sep 27, 2009 at 9:59 AM, Guillaume C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> gpointer  
> // \*\*\*\*\*\*\*\*\*\*\*\* problem is this cast \*\*\*\*\*\*\*\*\*\*\*  
> dest = (gpointer)ptr;  
> } else{  
> rb\_raise(rb\_eTypeError, “not a pointer object”);  
> }  
> return dest;  
> #endif  
> }

So I guess the problem is the “gpointer” type of cursor property in  
GdkWindow is too imprecise for rg2, or at least for rg2’s  
implementation of properties use. Mistake or not, I don’t know, but  
I’ve filed in gnome bugzilla:

> **[Bug 596494 – New property "cursor" in 2.18's GdkWindow with wrong type?](https://bugzilla.gnome.org/show_bug.cgi?id=596494)**

–  
Guillaume C. - [NVC Communication Obstacles Game](http://zarb.org/~gc/)
