SDL_MOUSEMOTION is detecting movement when there is none

Hi…have searched google and the forums but have not found anyone with the same problem.

I suspect I am misunderstanding how SDL_PollEvent works.

In the following code when I replace SDL_MOUSEMOTION with SDL_QUIT, SDL_MOUSEBUTTONDOWN, or even SDL_MOUSEBUTTONUP
the code behaves as I would expect for each case.

However when I use SDL_MOUSEMOTION my program window only stays up for the 2 seconds delay I have put in and then the window closes and the program exits,

even if I didn’t move my mouse at all, or even touch it.

I start the program using the keyboard in a Windows console window, so don’t touch the mouse at all before the program starts.

I was thinking that perhaps the program was taking existing events from a window buffer or something like that when it starts and that maybe I should clear before using SDL_PollEvent.

But from reading different articles on SDL_PollEvent it’s my understanding that this isn’t necessary, so I guess I am just missing something.

Any help or comments is appreciated, thank you.


SDL_Surface *screen = NULL;
SDL_Event event;

int main( int argc, char* args[] )



SDL_Delay( 2000 );

bool quit = false;

while( quit == false )
while( SDL_PollEvent( &event ) )
    if( event.type == SDL_MOUSEMOTION )
        quit = true;

SDL_FreeSurface( screen );

return 0;


Probably due to implementation decisions in the underlying operating

You can probably capture the initial position using SDL_GetMouseState(),
and only process “mouse moves” when the position reported by
SDL_MOUSEMOTION is different from the last known co-ordinates - essentially
the same workaround suggested in the link.On 7 April 2012 16:16, TonyBalony wrote:


Any help or comments is appreciated, thank you.

Thanks Brian…thought it might be something like that…your link clarifies this…and thanks for suggestion to work around.