Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Screen goes black.
- - By onnoowl Date 2013-05-15 13:04
I've worked with Gosu for a while without this happening, and I don't know what's causing it. I'm trying to simulate evolution. This program creates lots of little creatures and breeds them together, kills off the slow ones, keeps the fast moving ones, and eventually they should evolve into well designed fast travelling creatures.
As the program evaluates the speed of each creature, it opens up a gosu window, and runs it for about 3 seconds to see how far the creature goes. The problem I'm having is that occasionally/randomly, the entire window goes black and shows nothing.
If you guys could figure out what's causing this, that would be great.
(Note: My window class is called Simulation and is towards the bottom of the evolvingCreatures.rb file)
Attachment: evolutionAI.rb (3k)
Attachment: evolvingCreatures.rb (8k)
Parent - - By oli.obk Date 2013-05-15 14:35
does the program keep running?
add some console-output each frame and check whether that also stops :)
Parent - - By onnoowl Date 2013-05-15 14:39
The update function and the draw functions are still called. I did notice that if I comment out @creature.draw(self) it does not turn black anymore. The weird thing is even if I comment out anything in the draw function for Creature, so the function does nothing, I still get the bug.
Parent - By lol_o2 Date 2013-05-15 18:56
The possibility would be that @creature has wrong class object assigned, but it seems fine.
Try to move the draw code into Window's update to check if it still turns black with no exception. Such issue was in older versions of Gosu.
Parent - - By jlnr (dev) Date 2013-05-16 12:38
There was (is?) a bug in Gosu where an exception thrown in draw or other callbacks would be silently swallowed. Please try adding a begin … rescue … end block around your method implementations, and let me know if this problem still exists.
Parent - - By onnoowl Date 2013-05-16 14:16
I tried that, but it made no difference.
The rescue block is never running.
Here's the new draw block I tried:
  def draw
      coord = vec2(0, 0) - @drawOffset
      coord = vec2(coord.x % $size.x, coord.y % $size.y)
      @img.draw(coord.x, coord.y, 0, @imgScale.x, @imgScale.y)
      coord2 = coord - vec2($size.x, 0)
      @img.draw(coord2.x, coord2.y, 0, @imgScale.x, @imgScale.y)
      # c = 0xff333333
      # draw_quad(0, 0, c, $size.x, 0, c, $size.x, $size.y, c, 0, $size.y, c, 0)
      @creature.draw(self, @drawOffset)
      puts "Error"
      puts $!.backtrace
Parent - - By lol_o2 Date 2013-05-16 18:14
Check this subject:

Solution looks like this:

some bad drawing code...

rescue Exception => e
puts e, e.backtrace

I think 'Exception' after rescue is what you need.
Parent - By onnoowl Date 2013-05-16 21:18
The draw function does not seem to be throwing any sort of exception. When the screen goes black, the rescue function does not trigger.
However, I can prove that the rescue function is in fact doing it's job, because if I try to interrupt the program (ctrl C) it prints the interruption error message and then just keeps on going.
The draw function is not throwing any sort of error. What else could be causing the blackness?
Up Topic Gosu / Gosu Exchange / Screen goes black.

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill