Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Combination AltGr-number crashing with PL layout

This thread is locked; no one can reply to it. rss feed Print
Combination AltGr-number crashing with PL layout
Marek Ratajczak
Member #8,379
March 2007

Hi All,
This is Windows (XP, Server 2003 or whatever), Allegro 4.2.1. My application is running well until I touch AltGr-1 , doesn't matter if NumLock is active or not. It's working well if current keyboard layout is e.g. US. If is switched to PL (Polish programmer), is crashing. I cannot find a bug, looks like it's somewhere inside Allegro keyboard module. Before I have a chance to debug keypressed() or readkey() , it's crashing. If I don't install_keyboard(), it doesn't crash, but of course I cannot use keyboard.
I cannot remind myself I had such a problem with Allegro 4.0...4.1 what I used for couple of years, or not. But it was intentionally done to could type AltGr-number to select special ASCII characters. Now, just after first AltGr-1 is crashing, no even chance to type the rest of code, e.g. AltGr-1-3-5. Or maybe same problem was before, and I just used Alt instead of AltGr ? I don't need such a way to type extended codes anymore, I have all mapped already with AltGr-A.......z, so I'd like to just unable this killing combination, what somebody can press even by mistake.
Can anyone have any idea where's the problem or how to solve a problem?

Kind Regards,
Marek.

Elias
Member #358
May 2000

Would be nice to confirm it with the newest version, even if there's no changes relate to this as far as I know.

Anyway, to find the problem, you need to use a debugger and find out in which line of the source code it crashes (not sure how to do that in Windows, in Linux you'd use the debug library and just run the program in gdb).

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

GnuDeBugger works in Windows too. What compiler are you using? I think the binary installation of MinGW comes with gdb. Here is Documentation for GnuDebugger
Like Elias said , compile your program with the -g or -ggdb flags and then link the object codes together using -lalld to link to the debugging version of Allegro's library. Start the Windows 'cmd' interpreter. (Start button , run command , then type "cmd" and press return)
(
Your path needs to include your compilers \bin subdirectory so that it knows where to run gdb from. You can do that with this command :
set PATH=bin_directory;%PATH%
Make sure to include ';%PATH' at the end so it adds it to the existing path.
)
Now use 'cd directory_name' to change to your programs directory. Then enter : "gdb program.exe".
Then from inside the GnuDeBugger enter "run" and it will start your program. Now press the AltGr key and your program will crash , causing gdb to catch the exception. In gdb , enter "bt" or "backtrace" to see a list of all the stack frames with frame #0 being the innermost frame where the program was executing at the time of the crash. This will tell what frame(function) crashed. If you want to see the values of all the variables at this time , enter "bt full" or "backtrace full". If you only want to see the values of all the variables in the innermost N frames , type "bt N full" or "backtrace N full".

Marek Ratajczak
Member #8,379
March 2007

Hi,
I found solution, and maybe I found a bug in Allegro.
So, on some national keyboard leyout, combination AltGr-End is treated as Ctrl-Alt-End, what is a way to call Runtime library to close the application, for use in emergency. AltGr-End means the same as AltGr-1, doesn't matter what is the status of NumLock key. So pressing AltGr-1 (or AltGr-End) closes application. At least such an effect is on PL (programmer) keybord.

Solution is to change flag: three_finger_flag to false.
After change, program doesn't crash, or rather - is not killed by runtime library.
In the manual is writte:

(...)
extern int three_finger_flag;

The DJGPP keyboard handler provides an 'emergency exit' sequence which you can use to kill off your program. If you are running under DOS this is the three finger salute, ctrl+alt+del. Most multitasking OS's will trap this combination before it reaches the Allegro handler, in which case you can use the alternative ctrl+alt+end. If you want to disable this behaviour in release versions of your program, set this flag to FALSE.
(...)

All is truth, but maybe this description should be extended for Ctrl-Alt-End and AltGR-End as well.

By the way: of course I use debugger, and in this case I spent a couple of hours using it to find the source of problem. No success, because this "bug", if it is a "bug", is inside Allegro library, and I haven't access to debug information using bunary alleg42.dll.

I use compiler and debugger Microsoft Visual Studio .NET 2003 Architect (co MSVC 7.1).
Maybe my investigation will be useful for somebody....
Marek.

Elias
Member #358
May 2000

Thanks for finding this out.

There's this code in Allegro (src/win/wkeybd.c):

1/* if not foreground, filter out press codes and handle only release codes */
2 if (!wnd_sysmenu || !pressed) {
3 /* three-finger salute for killing the program */
4 if (three_finger_flag && (_key_shifts & KB_CTRL_FLAG) && (_key_shifts & KB_ALT_FLAG)) {
5 if (scancode == 0x00) {
6 /* when pressing CTRL-ALT-DEL, Windows launches CTRL-ALT-EVERYTHING */
7 ignore_three_finger_flag = TRUE;
8 }
9 else if (!ignore_three_finger_flag && (scancode == DIK_END || scancode == DIK_NUMPAD1)) {
10 /* we can now safely assume the user hit CTRL-ALT-END as opposed to CTRL-ALT-DEL */
11 _TRACE(PREFIX_I "Terminating application\n");
12 abort();
13 }
14 else if (ignore_three_finger_flag && scancode == 0xff) {
15 /* Windows is finished with CTRL-ALT-EVERYTHING - lets return to normality */
16 ignore_three_finger_flag = FALSE;
17 _key_shifts = 0;
18 }

So, it looks like NumPad 1 is even specifically tested against. And already some magic is needed for other cases where it would be wrongly detected. Not sure what to do about this new case thoguh.

Therefore, my proposed solution for future versions of Allegro would be to remove the Ctrl-Alt-End stuff completely. It was useful in the days of DJGPP, as DOS provided no way to kill a running program, but today this is completely useless as each OS has a task manager where you can kill the program.

--
"Either help out or stop whining" - Evert

Go to: