If the block used on Glib.timeout method access some member variable one line before it returns, the return value get some memory garbage and GTK think it's true, not false.
How to reproduce
Compile and run the following code with -Dpreview_mt.
require "log"
require "gobject/gtk/autorun"
window = Gtk::Window.new(title: "Hello World!", border_width: 10)
window.connect("destroy", &->Gtk.main_quit)
button = Gtk::Button.new label: "Hello World!"
button.connect("clicked", &->window.destroy)
window.add(button)
window.show_all
class Foo
@var = "hey"
def bar
spawn do
puts "Hi, I'm a new thread."
GLib.timeout(0) do
puts "I'm on main thread"
# access instance vars inside the block before the return call creates the problem
# comment this line and it works
@var = "ok"
# If uncomment this line, everything works too.
# Log.info { "fix" }
false
end
end
end
end
f = Foo.new
f.bar
If the block used on
Glib.timeout
method access some member variable one line before it returns, the return value get some memory garbage and GTK think it's true, not false.How to reproduce
Compile and run the following code with
-Dpreview_mt
.