4

I have a timer which calls a method (perform_step) every second. perform_step does some computation and invalidates my window. This works well initially but after a small number of iterations the on_expose_event of the window isn't triggered. From debugging I discovered the window invalidation method had been called, but the event handler isn't entered.

Any ideas what might cause this? Here are some things I've discovered that might be helpful:

  • When the computation in perform_step is shorter, things break down after less iterations.
  • Things break down after the same number of iterations every time.
  • Moving the mouse over the window keeps things from breaking down. If I constantly move the mouse over the window things will run forever. It seems to "reset" the counter. If things would break down after 10 iterations and on the 9th iteration I move the mouse over the window, things then break down on the 19th iteration.

Here a code snippet:

bool SimDisplay::on_button_press_event(GdkEventButton* event) {
  Glib::signal_timeout().connect( sigc::mem_fun(*this, &SimDisplay::perform_step), 1000 );
}

bool SimDisplay::perform_step() {
  world->step();
  //on the last iteration this is called but on_expose_event is never reached
  get_window()->invalidate(true);
}

bool SimDisplay::on_expose_event(GdkEventExpose* event) {
  ...
}
  • What if you do your counting /without/ using `signal_timeout`? Does it work correctly then? – Christian Smith Jan 10 '12 at 22:00
  • @senshikaze I've tried many ways to do the computation without using `signal_timeout` and have found that any method which should run forever breaks down after a small number of iterations. For example, I've tried (unsuccessfully) calling `perform_step` at the bottom of 'on_expose_event`. – Travis Martin Jan 17 '12 at 16:17

1 Answers1

1

Your on_button_press_event() is missing a return statement; make sure all your handlers are returning the proper thing.

unwind
  • 391,730
  • 64
  • 469
  • 606