jhass / crystal-gobject

gobject-introspection for Crystal
BSD 3-Clause "New" or "Revised" License
127 stars 13 forks source link

Boolean return value get messed on signals if using member variable one line before #70

Closed hugopl closed 4 years ago

hugopl commented 4 years ago

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
jhass commented 4 years ago

Huh, even after 55df329e31cac8b1741a8302fdeab18e028a3a72?