Re: [AD] Breakpointing an app in the MSVC 6 debugger can get a key to be stuck in Windows 2000

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Peter Wang wrote:
On 2005-12-28, Andrei Ellman <ae-a-alleg@xxxxxxxxxx> wrote:

The following test program demonstrates a problem with the keyboard driver when debugging an app with MSVC 6 under Windows 2000. The program is supposed to display a message when the F2 key is held down and clear it when it is not held down. However, if I am debugging the program using the MSVC 6 debugger and I place a breakpoint on the line that is only supposed to be execuded if key[KEY_F2], then when I press F2, the compiler stops at the breakpoint, but if I release F2 before I resume, then the F2 key appears to be stuck. Only pressing F2 again can unstick it. Even pressing other keys does not unstick it.


Actually, this is the behaviour I would expect.  I don't know why
Windows 98 acts differently.

You can try this test.  Using a windowed graphics driver, set a
SWITCH_IN and SWITCH_OUT callback with set_display_switch_callback() and
see if the callback is called before and after you enter the breakpoint.

I think what may be happening under Windows 98 is that the window
receives the WM_ACTIVATE message, which is handled in wwnd.c, which
calls _win_switch_out(), which calls key_dinput_unacquire() which clears
the key[] array.  Perhaps that doesn't happen under Windows 2000.


I tried the test, but it appears that in both Windows 98 and Windows 2000, neither the SWITCH_IN or SWITCH_OUT callbacks are called when the breakpoint is reached. However, when I bring another app to the foreground, the SWITCH_OUT callback is called, and when I switch back to the app, the SWITCH_IN callback is called.

I have attatched my updated test-app with the callbacks.

Under Windows 2000, I am using Direct X 9.0c, and under Windows 98, Direct X 8.1


AE.
/***************************************************************************
 *
 * breakpointkbdtest.c
 * Test program to show the Allegro keyboard handler failing to release a key if it was released during a break by the debugger.
 *
 **************************************************************************/


/****************************************************************************
 Includes
 */

#include <allegro.h>


/****************************************************************************
  Types
 */

typedef int TeBool;


/****************************************************************************
 Defines
 */



void 
teDisplaySwitchInCallback(void)
{

	TRACE("Switching IN\n");

}



void 
teDisplaySwitchOutCallback(void)
{

	TRACE("Switching OUT\n");

}




TeBool
teSetupGfx()
{

	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);		

	set_palette(desktop_palette);
	

	if(set_display_switch_callback(SWITCH_IN, teDisplaySwitchInCallback))
	{
		TRACE("Error setting up the switch-in callback.\n");
		return FALSE;
	}


	if(set_display_switch_callback(SWITCH_OUT, teDisplaySwitchOutCallback))
	{
		TRACE("Error setting up the switch-out callback.\n");
		return FALSE;
	}

	return TRUE;
}



void
teCleanupGraphics()
{
	remove_display_switch_callback(teDisplaySwitchOutCallback);
	remove_display_switch_callback(teDisplaySwitchInCallback);
}



void
teDoTest()
{
	TRACE("Starting test...\n\n");

	
	textout_ex(screen, font, "Hold down F2 to display some text", 0, 0, 1, 0);


	while(!key[KEY_ESC] && !key[KEY_SPACE])
	{
		if(key[KEY_F2])
		{
			// Place a breakpoint on the line below to see F2 getting stuck on Windows 2000
			textout_ex(screen, font, "F2 is pressed", 30, 20, 0, 1);
		}
		else
		{
			rectfill(screen,30,20,30+(13*8),20+(1*8),0);
		}
	}


	TRACE("\nEnding test...\n");
}



TeBool
teSetup()
{
	if(allegro_init())
	{
		TRACE("Error Initialising Allegro.\n");
		return FALSE;
	}


	if(install_keyboard())
	{
		TRACE("Error Initialising Keyboard.\n");
		return FALSE;
	}


	if(!teSetupGfx())
	{
		TRACE("Error setting up the graphics.\n");
		return FALSE;
	}


	return TRUE;
}



void
teCleanUp()
{
	teCleanupGraphics();

	remove_keyboard();

	allegro_exit();
}



int main(void)
{
	if(!teSetup())
	{
		teCleanUp();
		return -1;
	}


	teDoTest();


	teCleanUp();

	return 0;
}
END_OF_MAIN();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/