Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Gosu::Window#tick doesn't raise error.
- - By Andrek Date 2021-04-22 17:07
I'm working with Event Machine and Gosu so i'm using Gosu::Window#tick to make them work together and everything is fine till a error occurs in Gosu Loop(tick) and doesn't raise it and the Gosu::Window get bugged, i can't debbug my code so i'm stuck!

Sample code:
require 'eventmachine'
require 'gosu'

class Window < Gosu::Window
  def initialize
    super(640, 480)
  end
  def update
    0 / 0 # Generate error.
  end
end

$window = Window.new

EM.run do
  EM.add_periodic_timer(1 / 60.0) { $window.tick }
end


I'm following Using EventMachine with GTK+ and Using EventMachine with Qt
so i think this is the correct way.

Note: EM.add_periodic_timer is not a thread so Gosu::Window#tick can work correctly.
Parent - - By cyberarm Date 2021-04-24 13:24
Thanks for reporting this issue Andrek!
I've submitted a patch to Gosu that should resolve this issue.

https://github.com/gosu/gosu/pull/594
Parent - - By Andrek Date 2021-04-24 13:30
Thanks! I'll wait for that, while I have the solution that I said rencently.
Parent - - By cyberarm Date 2021-04-24 13:45
You can add this patch directly to your Gosu::Window subclass without needing to wait for a release:

require 'eventmachine'
require 'gosu'

class Window < Gosu::Window
  def initialize
    super(640, 480)
  end
  def update
    0 / 0 # Generate error.
  end

  alias_method :tick_internal, :tick
  def tick
    tick_internal

    if defined? @_exception
      raise @_exception
    end
  end
end

$window = Window.new

EM.run do
  EM.add_periodic_timer(1 / 60.0) { $window.tick }
end
Parent - By Andrek Date 2021-04-26 13:50
Back to working with this, i checked the pull request and use that version instead this because i'm using Ruby 3.

Thanks a lot :)
Parent - By Andrek Date 2021-04-24 13:25
I tested Gosu::Window#tick alone and realized that is its fault and EventMachine has nothing to do here, for now i'm catching errors in Gosu::Window#update by my self using this:

require 'eventmachine'
require 'gosu'

class Window < Gosu::Window
  def initialize
    super(640, 480)
  end
  def update
    begin
      0 / 0 # Generate error.
    rescue => e
      p e
      self.close
      EM.stop
    end
  end
end

$window = Window.new

EM.run do
  EM.add_periodic_timer(1 / 60.0) { $window.tick }
end


Is there a way to check if Gosu::Window is closed? want to:
EM.add_periodic_timer(1 / 60.0) { $window.tick unless $window.closed? }
Up Topic Gosu / Gosu Exchange / Gosu::Window#tick doesn't raise error.

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill