Odd mouse event generated on init

Hi everyone,

The mouse relative and absolute coordinates appear to be always equal for
the first mouse event. Also, there is always a mouse event generated when
grabbing the mouse. Isn’t that odd? That causes my small test programs using
mouse input not to init as I intend them to.

Here’s a small program illustrating what I’m saying. It quits right away
because a mouse event is detected. I wouldn’t expect mouse events to occur
unless asking for it explicitely (moving mouse, warp call and such).

My newbie self thanks you in advance for your kind help!

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480

int main(int argc, char *argv[])
{
SDL_bool exit_flag = SDL_FALSE;
SDL_Surface *screen;
SDL_Event event;

if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ))
{
fprintf( stderr, “Unable to init SDL: %s\n”, SDL_GetError() );
exit( 255 );
}
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_HWSURFACE |
SDL_DOUBLEBUF );
if (!screen)
{
fprintf( stderr, “Unable to set resolution: %s\n”, SDL_GetError() );
exit ( 255 );
}

SDL_WM_GrabInput( SDL_GRAB_ON );

do {
if (SDL_PollEvent( &event ))
{
switch (event.type)
{
case SDL_MOUSEMOTION:
{
fprintf( stderr, “mousex = %d, mousey = %d\n”, event.motion.x,
event.motion.y );
fprintf( stderr, “relx = %d, rely = %d\n”, event.motion.xrel,
event.motion.yrel );
exit_flag = SDL_TRUE;
break;
}
}
}
} while (!exit_flag);

SDL_FreeSurface( screen ); // may be before or after SDL_Quit
SDL_Quit();
}_________________________________________________________________
MSN Messenger : discutez en direct avec vos amis !
http://messenger.fr.msn.ca/

Philippe Anctil wrote:

Hi everyone,

The mouse relative and absolute coordinates appear to be always equal
for the first mouse event. Also, there is always a mouse event
generated when grabbing the mouse. Isn’t that odd? That causes my
small test programs using mouse input not to init as I intend them to.

Here’s a small program illustrating what I’m saying. It quits right
away because a mouse event is detected. I wouldn’t expect mouse events
to occur unless asking for it explicitely (moving mouse, warp call and
such).

Well, arbitrary events can happen at any time, that’s why they are
events. It’s your job to catch them correctly. Maybe you could poll all
the events you got during init before entering the main loop.

Also, always use while() to poll events. Using a simple “if” will pump
only one event from the event queue, while there could be more than one.
Events will then start to accumulate in the event queue until everything
blows up :slight_smile:

Stephane

Hi everyone,

The mouse relative and absolute coordinates appear to be always equal for
the first mouse event. Also, there is always a mouse event generated when
grabbing the mouse. Isn’t that odd? That causes my small test programs using
mouse input not to init as I intend them to.

In the next release there shouldn’t be any relative motion in the first mouse
event. You can check out the code in CVS and make sure it’s working well for
you.

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment