Hello! I am developing my first small game using Allegro5, and I am having an issue with the al_wait_for_event instruction. The code gets stuck on the instruction every... 4 seconds for like 0.5-1 secs. And after having stopped 4 or 5 times, it gets permanently stuck until it crashes.

Would really aprecciate some help with this, I am so annoyed.

Thanks!!!

Eric Johnson

Nothing immediately jumps out at me, so I'm not too sure what the problem is. One thing I would suggest is changing if(draw) to if(draw &&al_is_event_queue_empty(event_queue)) though.

EditActually, I see you had al_is_event_queue_empty(), but it's commented out.

I can't compile this without all the files. Could you provide GameUtils.h and Game.h, along with its corresponding source files?

Elias

I didn't look at anything else but you clearly don't want this as 1 / 60 will be identical to 0 in C++: al_create_timer(1/60);

Chris Katko

And to clarify that a little bit.

1 / 60 = 0 because 1 and 60 are both integers.

You'd need 1.0 / 60.0 or 1F / 60F to tell the compiler to treat those constants as floating point numbers.

Sidenote: You might be able to get away with only one of them having .0, but I never tested that and I'm not sure the automatic type promotion rules of C++. If you start the left-side with 1.0 and then divide by 60 (no decimal point), I would imagine it'd be promoted to float. But you might as well leave all of the constants with decimals to clarify you intend the number to be a float, to any human reader. Likewise, I wonder what happens if you start with an integer, and then divide by a floating point constant ala (1 / 60.0).

One thing I would suggest is changing if (draw) to if (draw && al_is_event_queue_empty(event_queue)) though.

Not getting why do we need to check if the queue is empty at all. I mean, I understand it, but I'm not understanding it as much as I would. I commented it when I was trying to solve the problem mentioned.

Thanks you all again!

Elias

If you don't have the al_is_event_queue_empty() but are receiving more than 60 events per second (easy with mouse/joystick events), you would delay your input more and more. You always draw 60 times per second then handle a single event afterwards. The check just makes sure to always handle all events before drawing the next time.