Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Gosu app hangs after the first update cycle
- - By udmurt Date 2011-07-30 13:17
Hi all,

I'm having troubles running a simple Gosu app (or I'm missing something really obvious). My application hangs after the first update loop. Here's the code for the app:
require 'rubygems'
require 'gosu'

class SimpleWindow < Gosu::Window
  def show
    super
  end

  def update
    puts "Hi there!"
  end
end

puts "Before the init"
window = SimpleWindow.new(640, 480, false)
puts "Before the loop"
window.show

I expect to see:
console> Before the init
console> the loop
wm> 640x480 window
console> Hi there!
console> Hi there!
console> Hi there!
etc

However, having no luck, the actual result is:
$ ruby simple.rb
console> Before the init
console> Before the loop
wm> 640x480 window
console> Hi there!
app hangs -- I even cannot Ctrl-C it -- have to it kill -9.

I would much appreciate any help to find out the problem.

My env:
* Gentoo x64
* XMonad
* ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
* Gem list:
chipmunk (5.3.4.3)
ffi (1.0.9)
gosu (0.7.34)
nice-ffi (0.4)
rake (0.8.7)
rake-compiler (0.7.9)
rdoc (3.8)
ruby-sdl-ffi (0.4)
rubygame (2.6.4)
rubygems-update (1.8.6)
Parent - - By jlnr (dev) Date 2011-08-01 08:57
Sounds to me as if it might hang inside the first 'draw'. Do other OpenGL applications work as expected? Do you have any major WM settings you can try? Ubuntu used to have a lot of trouble with the compositing WM, sometimes things worked when using the old fallback.
Parent - - By udmurt Date 2011-08-06 19:16 Edited 2011-08-07 14:00
That's interesting -- in the library method WindowX#doTick has the loop: while (XPending(display)) { ... }; and XPending(display) on my machine always returns 1, though I have no active events in the queue (at least I think so). That resulting in to infinite loop and "hang" of my app.

UPD: event.type in inf. loop equals to 102
Parent - - By jlnr (dev) Date 2011-08-10 23:17
That would be:
#define LeaveWindowMask      (1L<<5) 
#define PointerMotionMask    (1L<<6) 
#define MotionNotify    6


However, why this would reappear infinitely in a loop, I don't know. Does it change anything if you are not moving the mouse at all?
Parent - - By frostiebek Date 2011-08-24 17:44
Same problem here on Ubuntu 32bits (2.6.38-11-generic)
Any work around available ?
Parent - - By jlnr (dev) Date 2011-08-24 18:20
If this is a common problem, then I will schedule a workaround - maybe just process 10 events per loop or something...
Parent - - By frostiebek Date 2011-08-25 10:19
Here is what I did to unlock the loop :

for (int i = XPending(display); i >= 0; --i)
{
     ::XEvent event;
     XNextEvent(display, &event);

     [...]
}


But the event queue is still spammed with event type 103 ...
Parent - - By jlnr (dev) Date 2011-08-26 02:50
What happens if you make that int i = std::min(XPending(display, 10)? Do other events still get through?
Parent - - By frostiebek Date 2011-08-26 12:09
I made a mistake in my previous post :

for (int i = XPending(display); i > 0; --i)

With >= 0 the program was waiting for a new event to be queued and thus blocked the program execution for several ms (due to the behavior of XNextEvent).
Now I have a decent frame rate !

Though there is still one 103 event present in the queue for each tick ...

What happens if you make that int i = std::min(XPending(display, 10)?

Nothing, because most of the time there is less than 10 events in the queue per tick.
The problem was the behavior of the loop that will always consume new events posted during the current tick, making it last forever when spammed.
Moreover the standard behavior of XPending may be to wait for a new event when the queue is empty... (not so clear in the man about that http://www.manpagez.com/man/3/XPending/).

Anyway, nice work on Gosu, after that little fix everything went ok :)
Parent - By jlnr (dev) Date 2011-08-26 16:21
Wow thanks, and interesting fix! My guess is that X11 simply simulates a Motion event if nothing else is going on, just to make mouse moving as smooth as possible. It's just curious that nobody else had a loop like me. Oh well, that's what I get for manually fiddling with X11 :)
Up Topic Gosu / Gosu Exchange / Gosu app hangs after the first update cycle

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill