Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro5: Event Queue Delay Problem

This thread is locked; no one can reply to it. rss feed Print
 1   2   3   4 
Allegro5: Event Queue Delay Problem
GaryT
Member #14,875
January 2013

I'm only getting the problem on Windows Vista and Windows 7. Not on XP.

Just to emphasize something once more for anybody testing this out: Very strangely I appreciate, but when having more that one call to a draw function, then for most runs of the program the delay largely disappears.

For example take the test program in pkrcel’s last entry: If I comment out the call to al_draw_textf() line 108, it makes the difference (most of the time on my two laptops anyway) of the delay being quite noticeable most of the time, and not noticeable at all. Just a very strange oddity I know, which somehow interrupts the true cause of the problem, but thought it very important to point out for anybody else trying to reproduce the delay issue.

Also, when using al_wait_for_event and using a timer (But No Vsync) there is absolutely no delay. So then, since my approach with using Vsync in the way I am doing is perhaps non conventional, then maybe this is why nobody else is noticing the delay issue. BUT if I enable Vsync with: al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE/ALLEGRO_SUGGEST) the problem's every bit as bad with al_wait_for_event and using a timer, as compared to the way I'm doing it.

So having said all that. It seems something is definitely buggy about Vsync which is affecting at least the Event Queue, specifically KeyDown events and probably others.

Also from Peter Wang's 1st reply, it seems it's very likely to do with: "input events are added to the queue by a background thread" as this explains perfectly the behaviour. That is the ALLEGRO logic of the loop is working correctly, but there's a definite delay from pressing a key to the events entering the queue.

Until this problem is officially recognised and fixed, I'm considering not using the event queue for just the key down events that control my characters when the game state is in play. I'm going to replace these particular key down events with checking the keyboard state instead. This way I can still time my game as I've been going on and on about, using the Vsync signal as I've previously mentioned.

I've heard Allegro4 doesn't have the events system and uses the keyboard state as I've suggested above. Also I've heard about key presses being missed, which I can understand why, but is it really that bad. If Allegro4 has been working great for all these years, surely it can't be that bad.

I'm going out to the pub now. See you later and Thank You. :)

Edgar Reynaldo
Member #8,592
May 2007
avatar

I tried again, and I can't reproduce it anymore. :/
(MinGW 4.5.0, A5.1.6 binaries, Vista, debug/release)

GaryT said:

So having said all that. It seems something is definitely buggy about Vsync which is affecting at least the Event Queue, specifically KeyDown events and probably others.

No, that's not true. Vsync works just fine and that has no bearing on the event queue. If the event queue is both simultaneously empty and backed up that means that its event source is not feeding it fast enough or perhaps on time, but I don't know what the delay would be.

pkrcel
Member #14,001
February 2012

i should have mentioned I am using VS2012, alas MSCV11...I think with last November's CTS update....I could try also with MingW and VS2010.

Given all of the answers here, and the fact that XP seems to be NOT showing the problem whatsoever something may be fishy in the backgournd thread not filling up the queue....but this MAY depend on some Windoes interface?

Gary woud you care to attach here your VS10 solution?

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

GaryT
Member #14,875
January 2013

Edgar said:

No, that's not true. Vsync works just fine and that has no bearing on the event queue"

You can't possibly know that Vsync works just fine on every system on all Windows versions. Also it's unlikely that it's only my two Laptops that are showing the problem. Having said that, both my Laptops are using the same MSCV 2010 and VS10 solution. So perhaps it could be settings within my solution properties settings that are the problem. I'm wondering now from pkrcels's last reply. ???

Edgar said:

If the event queue is both simultaneously empty and backed up"

What does this mean. I've never believed this to be true. How can it be. The queue or anything else can't be empty and have something in it at the same time. The whole point here as Peter pointed out and now pkrcel is considering, is that it might be the background thread is for some reason on perhaps only some systems and on only some windows versions, feeding the events to the queue with a varying time delay.

Yes pkrcel, I'm very happy for you to take a look at my VS10 solution. :)

I've uploaded the complete project folder to my sky drive, it's a zip file of about 10.8MB

I'm off to work now, but I'll check in from time to time.

Do you have an email I can send you a shared link to for my Sky drive.

Alternatively I can provide an email address for you to send me your email address for confidentiality.

Addition: I've increased the speed to 5 pixels because it's easier to notice. I've found the best thing to do to notice the delay is let the square move across the screen and tap the up and down keys about 1/3 second apart repeatedly. This way even if the delay is minimal, it's very easy to notice when the direction doesn't change immediately.

Please let me know and thank you. :)

Thomas Fjellstrom
Member #476
June 2000
avatar

If you re-read peter's post, you'll see what he was seeing was likely a bug in wine. Nothing to do with windows.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

GaryT
Member #14,875
January 2013

Probably Likely

I don't really care either way.

I just want to know how to fix the problem I'm getting. :P

Thomas Fjellstrom
Member #476
June 2000
avatar

I really haven't properly read all of your points. Mainly because the few I read made no sense to me. Same with the code.

Can you post a very minimal example that shows the problem reliably, and isn't broken like your original code?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

GaryT
Member #14,875
January 2013

What do you mean broken.

Besides the first While loop within the main loop which I put in, and have already criticized declaring it to be rubbish, the program couldn't be more simple. That's it's purpose, it's a test program of the simplest kind. Smiley Face. (I'm at work on XP and I can't add the little pics.

Thank you Thomas.

SiegeLord
Member #7,827
October 2006
avatar

I tried the code in the OP and pkrcel's post, and I could not reproduce the issue on Windows 7 with the git version of Allegro.

It looks like people who can reproduce this will need to hack away at Allegro's source and put some debugging output inside the keyboard routines. I could try producing one-off binaries to help, but I only have MinGW 4.7 installed.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

GaryT
Member #14,875
January 2013

Thank you SiegeLord.

If pkrcel doesn't manage to reproduce it from my VS10 Solution after receiving it, then I might try a compiler other than MSVC or a later version than MSVC10.

At least for now I might also just try reading the keyboard state for the main character control keys. At least this way I won't have come to a complete stop, and could attempt to sort what ever this issue is, out later.

Just a quick question about this control panel window I'm typing in: Is there an attachment feature for attaching files and zip's. On my Laptops I'm using explorer 9 and I don't know if the icons at the top of this window are supposed to display text when hovering over them. On XP using explorer 8 I can't even add the small pics(Sad Face). Might it be I should be using explorer 10.

If not then hopefully I'll be able to provide it to pkrcel and anybody else via email. Cheers(Smiley Face)

EDIT: When I get more experience I might also try building an ALLEGRO Package such as the new 5.0.9 version. But have no clue how to do that yet.

EDIT 2: Also anybody who receives my VS10 Solution (includes the whole project folder) will at that point have a copy of the .exe I've generated. You could copy it somewhere else before recompiling so you don't write over it. You could run this .exe to see if you can see the delay.

EDIT 3: And, you could compile the source code yourself using any compiler, and let me have a copy of your .exe. I would love to know the results of all this. (Smiley Face x 2)

Dizzy Egg
Member #10,824
March 2009
avatar

I still don't get your original code; if I press up start moving up, and don't stop until I press down, at which point keep moving down. If I press left it'll keep moving down but left as well.

I suspect buffoonery.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

pkrcel
Member #14,001
February 2012

Gary, feel free to send me the link at pkrcel(whackyroundsymbolusedforelectronicmail)gmailDOTcom

Yeah I know I am truly paranoic.

<= NOT paranoic.

Anyway you could also have uploaded just the solution (.sln) file to your post, it woudl suffice just for now.

But, just to clear all out, when I asked you for your MSV Csolution I've been thinking along the lines of Siegelord's post...IF there is a backgorund thread and Windows messaging system is involved, some security features may get in the way (namely to avoid someone log your keypresses).

Just a random though since Xp seems not to generate any problem and IIRC Vista/7 do habdle a little bit deeper the matter.

But as said, these are really random toughts.

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

GaryT
Member #14,875
January 2013

That's correct. The square just keeps moving. It's a very basic test program.

The problem is a delay in processing key presses as described throughout this thread.

The logic of the programs loop is working correctly. It seems that I'm sometimes getting a delay before the event key presses are entering the queue.

This has already been suggested and described in this thread (Smiley Face)

EDIT: I've sent the link pkrcel. Please let me know if you receive it ok.

As in my last reply to SiegeLord, I don't know how to attach files in this forum. I might be using the wrong version of explorer. Many Thanks.

pkrcel
Member #14,001
February 2012

Got it....I need to install the MSVC10 redistributable since you deploy DINAMICALLY linking to the C runtime libs....I strongly suggest to use the /MT option of all the available libraries... :-*

EDIT: ....aand indeed the VC2010 redistributable package does NOT contain DEBUG libraries..... ::)

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

GaryT
Member #14,875
January 2013

I have been Static Linking as per the Wiki tutorial.

Obviously I don't understand the complexities of all this, but the .exe runs on my XP computer which has no software on it in connection to any of this.

Yesterday I just downloaded Microsoft Visual C++ 2010 Express from their site on my other laptop, freshly downloaded the ALLEGRO 5.0.8 pre-built binary, and that was it. I then copied my solutions over, and I can now use this second Laptop I have, exactly the same as I've been doing so on my first Laptop.

My sincere apologies if I am completely missing the point. I probably am.

Please let me know if there's anything else you suspect I might be doing which might help.

Thank You Again. (Smiley Face)

pkrcel
Member #14,001
February 2012

And that's also what's your project setup, I see in the Debug Properties that you have specified "MT (Multi Threaded)"....so I am unclear as to why it's asking me the MSVCR100D.dll

But, as I said (actually I forgot to update my previous post, so nvm), the executable does not match the source code...this is what I see when running it.

{"name":"607396","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/8\/98586135d057555bce4545a509f831a8.png","w":656,"h":518,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/8\/98586135d057555bce4545a509f831a8"}607396

(so similar to Mike Geig's tutorial output :D )

...so it's entirely possible that this exe is comopiled with MD option...since there's also Allegro monolith DLL in the exe folder.

I see nothing fishy in your solution's option and such, i'll try my last resource, using the same compiler as yours (I'm runnig with MSVC11, namely Visual Studio 2012).

EDIT: just a stypEd question...in VS2010, which kind of project you selected when doing "new project"?

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

GaryT
Member #14,875
January 2013

Damn, What A Plonker I Am.

Sorry I forgot to sort this out. Shouldn’t be a problem though.

I modified an old Project folder deleting that .cpp file.

I accidentally forgot to recompile in debug mode.

The correct .cpp file is in there.

If you look in the release folder the correct .exe will be in there.

Also if you open the solution folder it should open in MSVC 2010 with the correct .cpp and in the project settings you should be able to see all the Static Link setting up as per the Wiki.

Again sorry for the miss communication on my part. (Very Naughty Face To Me)

EDIT: Windows application. Not console application.

pkrcel
Member #14,001
February 2012

Release Mode, yeah right.

Okay I tried your original EXE file and....tah-dah I can experience you problem as well!

the "cube" has a VERY noticeable delay and -some-everytimes it changes direction way after the keypress.

THIS has surely something to do with the kind of project you've setup...could those be "CLR console application" or "Win32 application"?

Would you try this with an "Empty Project" template, please?

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

GaryT
Member #14,875
January 2013

I'm EXSTATIC. Let me calm down for a minute.

Edit Yes I believe I've been selecting: Win32 application. There might have been other settings as well but I can't remember.

Anyway I'm at work and will have to wait until I get home in about 2.5 to 3 hours from now.

If your experiencing the same thing though and from what you've said, it's looking very exciting for me.

I'll report back when I get home.

I'm still feeling a bit queasy. Yippy. (A Face You've Never Seen Before)

pkrcel
Member #14,001
February 2012

Well, I tried to hack down a Win32 app template with my version of the code and in VS2012 it does NOT (It DOES, dumb me) replicate the exe behaviour.

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

GaryT
Member #14,875
January 2013

Awesome. Thanks so much for all this.

pkrcel
Member #14,001
February 2012

NOW I'm confused....after dablling with the win32app template and replication your problem with MY code (namely commenting out al_draw_textf does indeed show the delay in response)

...also MY ORIGINAL project shows the same behaviour!

I can swear for the life of me that this did not happen EVER in that project before trying this out.

Also: you can add a second and a THIRD call to al_draw_rectangle..this does NOT eliminate the lag as instead al_draw_textf does. :o

What the HELL is going on here?

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

GaryT
Member #14,875
January 2013

I'm in tears with laughter, hang on a minute I can't breath.

EDIT: I don't know what to say except: Thank God I'm not on my own.

I'll await your response and just don't know what's happening next. (That Simple Looking Face I Like To Pull)

pkrcel
Member #14,001
February 2012

Well, I could just go on and kill you on laugthers then.

Wanna know the better part of it? I did a clean reboot of the system, tried out my original code and....the problem persist, can't get rid of it EVER w/o resorting to the al_draw_textf.

Saying that I'm amazed is a serious understatement.

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

GaryT
Member #14,875
January 2013

Well I'm glad your on the case and thank you.

I'm still crying a bit though, but starting to calm down.

 1   2   3   4 


Go to: