Debugging AGS engine in MSVS 2015

Started by Crimson Wizard, Sat 14/10/2017 18:25:48

Previous topic - Next topic

Crimson Wizard

I always had this issue when debugging AGS engine in Visual Studio before: when you break the program execution (e.g. by placing a breakpoint in the code) there was always a delay of few seconds before VS begins to respond to mouse and keyboard input, like if something is locking the input. It was happening only once per debug session, when you break the program for the first time. I had a suspicion that it has to do something with how Allegro 4 works, but could never find anything related in the internet. That was mildly annoying, and in the abscence of solution I decided to just live with it.

Now when we switched to MSVS 2015 in the master branch, this issue became much worse. This input freezing does not go away. It looks like this: program stops at breakpoint, and everything seems to be okay: no extra CPU load, the cursor is flickering in the VS as normal, but as soon as I touch the mouse or press any key, everything freezes for several seconds. This repeats every time after any signal from input device. If I move mouse too much at once I have to sit and wait for a minute before I can even shutdown debugging session forcefully.

Apparently it affects whole system, not just MSVS, because switching to other program windows does not help.
I only found one possible workaround: if I start or continue debugging, then switch to another application quickly, before next breakpoint is hit, everything works normally. But doing this trick really wastes my time alot, besides it's a game of chance.

So, right now I am almost unable to debug the code in the master branch using MSVS debugger.

What confuses me also is that since we changed to MSVS2015 there had to be other people who also tried building and running the engine. Have anyone else noticed similar thing, or it's just me?

I remember finding some kind of solution in the web a long while ago, something about hacking a registry, and IIRC that kinda worked (although not 100%), but seems bit unreliable to me, also unfortunately I forgot what it was and how to search for it.


NOTE: this does NOT occur when debugging Editor, even if I put breakpoints in C++ native code.

EDIT2: After further testing I can confirm, a call to Allegro's function install_mouse causes mouse issues in the debugger, call to install_keyboard locks up keyboard input inside MSVS correspondingly.

EDIT3: Finally was able to find the threads on Allegro forums, confirming and explaining this issue:
https://www.allegro.cc/forums/thread/615043
https://www.allegro.cc/forums/thread/615012/1009606#target

QuoteAllegro grabs the system keyboard and mouse. So when the game crashes or reaches a breakpoint, the IDE pops up, but all mouse movements and keyboard events have a several seconds lag because the allegro handlers simply do not answer. Mouse buttons do not work at all. Imagine to single step like that.

UPD4:
Another couple of descriptions of the similar problem. I am not completely sure if the cause is same, but description of the symptoms match:
http://the-witness.net/news/2012/12/finding-and-fixing-a-five-second-stall/
https://stackoverflow.com/questions/9727327/windows-keyboard-hook-hangs-debugger


Alan v.Drake

I experienced the same, I thought there was some incompatibility with my system or a windows 10 update.
Mouse moved like a damn slideshow, had to move and pray my blind aim was true to close the damn window.
Can't remember if I found a way around it or just gave up debugging

- Alan

Crimson Wizard

#2
Ok, the workaround posted in one of those threads actually seem to work for me.

1. Open regedit and look for "LowLevelHooksTimeout" property. It should be in HKEY_CURRENT_USER\Control Panel\Desktop.
This is a time Windows waits for the low level hook function before it lets user input further. By default the value is 5000 ms.
2. Change it to something really small, like 100. Do not forget to restart Windows.

Now, the behavior I experience is this: as soon as breakpoint is hit, the mouse and keys act rather slowly in MSVS, yet still faster than before. After several seconds (or key-presses?) the lag goes away completely.

If you let game continue and hit breakpoint again later, same thing repeats although lag seem to go away faster this time. Still kinda annoying, but at least it's possible to work.

It's hard to tell whether this may cause any issues inside the engine or Allegro, but in-game controls seem to work anyway, so hopefully that's not too critical.

Still it would be nice to find a solution someday that does not require messing with Windows registry.

Crimson Wizard

#3
*Bump*
So, the solution I posted above works, but the registry parameter resets after a while (not sure when or why), and it's easy to forget about it and stuck in unresponsive debugger that locks the computer for 10 minutes (if you moved mouse or smashed keyboard too much).

Has anyone else heard about problems like these, and the better way to solve them?

SMF spam blocked by CleanTalk