GTK + window re-invalidation: crash after several steps

I have a timer that calls a method ( perform_step ) every second. perform_step does some calculations and invalidates my window. This works well initially, but after a few iterations, the on_expose_event window does not start. From debugging, I found that the window invalidation method was called, but no event handler was introduced.

Any ideas what might cause this? Here are some things that I have found to be useful:

  • When the calculation in perform_step shorter, everything happens after smaller iterations.
  • Things break after the same number of iterations every time.
  • Moving the mouse over the window causes things to collapse. If I constantly move the mouse over the window, everything will work forever. It seems like a "reset" counter. If something broke after 10 iterations, and at the 9th iteration I move the mouse cursor over the window, things then break at the 19th iteration.

Here's the 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) { ... } 
+4
source share
1 answer

Your on_button_press_event() missing a return ; make sure all your handlers return the correct thing.

+1
source

Source: https://habr.com/ru/post/1390113/


All Articles