0

I am making a TRON Game using Allegro, and in my game loop I have the following code:

    al_start_timer(game->timer);
    while(1) {
        al_wait_for_event(game->timer_queue, &evt);
        if(evt.type == ALLEGRO_EVENT_TIMER) ++timer; 
        if (!al_is_event_queue_empty(game->timer_queue)) continue;
        while(timer > 0) {
            --timer;
            process_keyboard_input(game);

            if(game->should_abort) {
                //program stops here
                al_destroy_timer(game->timer);
                return; //exits the game loop function and ends the game
            }
            // Colision checking
        }
    }

And then, below that code I have some colision testing that enables game->should_abort. But with some printfs I have discoreved that the program runs until al_destroy_timer(game->timer) is called. Is it possible the execution stopped because of some thread violation?

lucas_turci
  • 315
  • 1
  • 3
  • 12
  • Its unlikely that a race happens unless you are making some crazy stuff on the code below this. Try moving you program end variable to the `while(1)` construct to see if this affects it. That way the program exits at the faster way possible. – rlam12 Dec 15 '16 at 01:23
  • It still behaves the same. But if I move that, my game kind of lags, that's why I thought it had some thread issue. – lucas_turci Dec 15 '16 at 01:33
  • Try destroying the timer at the very end of the main function. Just before the return function. – rlam12 Dec 15 '16 at 01:37
  • I somehow solved it. When I initialized the timer with `al_create_timer(speed)`, I passed as parameter the double `speed = 1/8`. But then I changed it to `speed = 0.125`, and it worked, even though both are the same (at least they should be, right?) – lucas_turci Dec 15 '16 at 01:50
  • 2
    `1/8` is performing integer division; the result is `0`. Try `1.0/8` to perform floating-point division instead. – rcorre Dec 15 '16 at 02:09
  • Sorry for answering ~4 years late but that was indeed the problem, thank you! – lucas_turci Feb 07 '21 at 04:44

0 Answers0