# How to track "GRClosure invoking callback:..." errors?

**URL:** <https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692>\
**Category:** Ruby-Gnome 2\
**Created:** [March 1, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692 "2008-03-01T23:17:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 1, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/1 "2008-03-01T23:17:40Z")

</div>

Hi,

This one is driving me crazy. I’m using ruby-gnome2 0.16.0 on an 32-bit  
linux machine.

I’ve something like this  
class TestTable  
attr\_accessor :content\_types  
attr\_accessor :content\_columns  
attr\_accessor :view  
attr\_accessor :liststore

def initialize  
self.content\_types = String, Integer, String, STring, String  
self.content\_columns = [“hmm”,“int”,“a”,“b”,“c”]

```
self.liststore = Gtk::ListStore.new(*self.content_types)
self.view = Gtk::TreeView.new(self.liststore)
self.liststore.signal_connect("sort-column-changed"){ |me|
  c_id, order = self.liststore.sort_column_id
  puts "sort column changed: #{c_id} #{order}"
}

```

end  
end

The signal\_connect(“sort-column-changed”) parts causes the headache. For  
the first times it works, then I’ll get the warning  
./start.rb:19: warning: GRClosure invoking callback: already destroyed  
(line 19 in start.rb is Gtk.main )

I tracked down the problem to the Garbage collector. A GC.disable solves  
this issue… but then my program dosen’t free memory anymore which is  
not a good thing at all.

liststore is still there and liststore.sort\_column\_id is also updated.  
So I guess the signal-connect block has been deleted by the GC?

I wanted to create a test-case. But strangely I cannot reproduce this  
error in my test application which only removed my API part and  
simplified some things.

Any advise how to debug this?

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 2, 2008, 11:38am UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/2 "2008-03-02T11:38:05Z")

</div>

Hi,

could you post a (at least partial) working example, please.

Cheers, detlef

Am Samstag, den 01.03.2008, 23:17 +0100 schrieb Joachim G.:

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 2, 2008, 12:45pm UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/3 "2008-03-02T12:45:18Z")

</div>

Detlef R. wrote:

> Hi,
> 
> could you post a (at least partial) working example, please.

Ah, yes. I could finally track the problem down and make a demo. See  
attached file. Try changing the sort bars several time, in this test I  
need between 15 and 30 clicks.

The problem is caused by this: I’m using custom classes for formatting  
stuff, for example a Currency in a list, like this:

class EuroCurrency \< Float

# this seems cause the problem:

def self.fmt\_str(text)  
sprintf("%.2f",text.to\_f).gsub(".",",")+" Euro"  
end

end

At rendering I have this sniplet which calls the fmt\_str method if this  
one of my custom models:

if is\_custom\_class(i) == true  
str\_class = self.column\_types[i]

# that one seems to do the problem:

col.set\_cell\_data\_func(renderer) do |col, renderer, model, iter|  
renderer.text = str\_class.fmt\_str(renderer.text)  
end  
end

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 2, 2008, 2:28pm UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/4 "2008-03-02T14:28:22Z")

</div>

Hi,

i’ve reworked and simplified your example to this:

#!/usr/bin/ruby  
require ‘gtk2’

module EuroCurrency  
def fmt\_str(text)  
sprintf("%.2f",text.to\_f).gsub(".",",")+" Euro"  
end  
module\_function :fmt\_str  
end

class TestTable  
def initialize  
@column\_types = String, String, String  
@content\_columns = [“str”, “str”, “cur”]

# initialize table

```
@liststore = Gtk::ListStore.new(*@column_types)
@view = Gtk::TreeView.new(@liststore)
@liststore.signal_connect("sort-column-changed") do |me|
  c_id, order = @liststore.sort_column_id
  puts "sort column changed: #{c_id} #{order}"
end

```

end

def is\_custom\_class(i)  
@content\_columns[i] == “cur”  
end

def add\_row(data)  
row = @liststore.append  
i = 0  
data.each do |d|  
row[i] = d  
i = i +1  
end  
end

def render\_and\_attach(widget)  
i = 0  
@content\_columns.each do |name|  
renderer = Gtk::CellRendererText.new  
col = Gtk::TreeViewColumn.new(name, renderer, :text =\> i)  
@view.append\_column(col)  
col.sort\_column\_id = i

```
  if is_custom_class(i)
    col.set_cell_data_func(renderer) do |col, renderer, model, iter|
      renderer.text = EuroCurrency.fmt_str(renderer.text)
    end
  end

  i = i + 1
end
scrollwindow = Gtk::ScrolledWindow.new.add @view
widget.add scrollwindow

```

end

end

class GenericList \< Gtk::Object  
attr\_accessor :container  
type\_register  
def initialize(opts={})  
super()  
@container = Gtk::HBox.new  
@table = TestTable.new  
get\_data  
@table.render\_and\_attach(@container)  
end

```
def get_data
  i = 0

  50.times do
    @table.add_row(["asdf", "Na#{i}me", (i*5.2).to_s])
    i = i + 1
  end
end

```

end

window = Gtk::Window.new  
list = GenericList.new  
window \<\< list.container  
window.set\_default\_size 400, 400  
window.show\_all  
Gtk.main

now it works. What the real problem was i don’t know, sorry. What have i  
done?

- First i removed the unnecessary subclassing of Float for EuroCurrency
- Then i replaced all the self with @
- removed the Glade stuff
- setting all Column types to String
- many smal changes

HTH detlef

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 2, 2008, 4:42pm UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/5 "2008-03-02T16:42:51Z")

</div>

> - First i removed the unnecessary subclassing of Float for EuroCurrency
> - setting all Column types to String

Setting all columns are String actually does the job. But a string can’t  
efficiently sort numbers. (10… 104… 20 ) so my initial idea was to  
subclass Float or Integer. This actually works.

What is causing problems is the self.fmt\_string method inside my  
subclass of Float/Integer etc.

By doing something like this  
module Convert  
def fmt\_str(type,text)  
if type == EuroCurrency  
sprintf("%.2f",text.to\_f).gsub(".",",")+" Euro"  
end  
end  
module\_function :fmt\_str  
end

class EuroCurrency \< Float  
end

and on the renderer

str\_class = @column\_types[i]  
col.set\_cell\_data\_func(renderer) do |col, renderer, model, iter|  
renderer.text = Convert.fmt\_str(str\_class,renderer.text)  
end

I don’t get that error. Strange…

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 3, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/6 "2008-03-03T16:26:53Z")

</div>

After more weirdness about this error I “fixed” it

def connect\_sort\_update  
unless @sort\_update\_handler == nil  
@liststore.signal\_handler\_disconnect(@sort\_update\_handler)  
end  
@sort\_update\_handler =  
@liststore.signal\_connect(“sort-column-changed”){ |me|  
col\_id, ordering = me.sort\_column\_id  
puts “sort column changed: #{col\_id} #{ordering}”  
connect\_sort\_update  
}  
end

On every signal call, it disconnects the signal and reconnects it. This  
way it doesn’t seem to be collected by the GC.  
Although this is very ugly, it solves my problem.

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 3, 2008, 6:34pm UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/7 "2008-03-03T18:34:27Z")

</div>

so you think that GC freed the signal handler procedure, and that caused  
the GRClosure errors?

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 4, 2008, 5:51am UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/8 "2008-03-04T05:51:20Z")

</div>

Yes, that seems to be the cause of the error. Search google for the  
error message; we’ve discussed this before and there’s a patch in  
launchpad that seems to fix it.

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 3, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/9 "2008-03-03T22:29:14Z")

</div>

Dobai-Pataky BÃ¡lint wrote:

> so you think that GC freed the signal handler procedure, and that caused  
> the GRClosure errors?

I think so, but I’m not sure what exactly happens there.  
It seems that it never get collected when not emitted. When signal is  
emitted (at least) once, it seems that it’s being freed up by the next  
GC run.

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 4, 2008, 7:39am UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/10 "2008-03-04T07:39:10Z")

</div>

Hi,

2008/3/2, Joachim G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Detlef R. wrote:
> 
> > Hi,
> > 
> > could you post a (at least partial) working example, please.
> 
> Ah, yes. I could finally track the problem down and make a demo. See  
> attached file. Try changing the sort bars several time, in this test I  
> need between 15 and 30 clicks.

I’ve fixed this problem in trunk.  
Your test program should work well without any changes.

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [March 4, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/how-to-track-grclosure-invoking-callback-errors/130692/11 "2008-03-04T14:10:23Z")

</div>

Kouhei S. wrote:

> I’ve fixed this problem in trunk.  
> Your test program should work well without any changes.

Yes, works!

Thank you!
