Jump to content
  • Advertisement
Sign in to follow this  

[resolved?] SDL_WarpMouse supresses SDL_MOUSEMOTION events when a button is held?

This topic is 2938 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, I have a fairly standard control scheme with a peculiar problem. In the Event loop, I check for mouse motion like this:
	case SDL_MOUSEMOTION:
		mouse_x = event.motion.x;	mouse_y = event.motion.y;
		break;



And in my game code, I control something like this (xm,ym being the center of the screen):
	ctrl.movexrel += (mouse_x - xm);
	ctrl.moveyrel -= (mouse_y - ym);
	SDL_WarpMouse((Uint16)xm, (Uint16)ym);



This all works perfectly well, until I press and hold one of the mouse buttons (e.g. to fire). That causes the thing to stop moving. In fact, in the debugger I found out that no SDL_MOUSEMOTION events are generated at all when a button is held! But if I remove the SDL_WarpMouse then it does generate these events regardless of the button state. What the ****? Has anybody seen this before (and hopefully solved it)? It boggles my mind... edit: And before anybody suggests it, I have already tried SDL_WM_GrabInput. It's what you're supposed to use for this but it produces very jerky motion, like it's only polling the mouse with 20Hz frequency instead of 100-200 or whatever the normal rate is. It's practically unplayable. (Does it hook into DirectInput or something?) edit2: "Resolved", yet perplexing. Of all things it seems to be some sort of a timing issue. Moving the SDL_WarpMouse to directly after the event loop fixed it. The error seems to occur if SDL_WarpMouse is called right before SDL_PollEvent, so a sequence like pollevents-render-update-warpmouse needed to be rearranged to pollevents-warpmouse-render-update. Really weird, and the "solution" doesn't feel very reassuring. [Edited by - Fingers_ on March 16, 2008 7:06:40 PM]

Share this post


Link to post
Share on other sites
Advertisement
I was having a very similar issue and your 'solution' seemed to work for me as well. I thought I'd document it here in case others have the same problem.

Basically, I set SDL_GrabInput to limit the mouse to the window. But then as the mouse gets to the end of the screen, it stops generating SDL_MOUSEMOTION events so I can't move my crosshair anymore (I am adding the mouse vel to the crosshair's current position each frame).

Sooooo, I decided to center the mouse using SDL_WarpMouse after getting it's velocity. But this generates SDM_MouseMotion event with a velocity vector that exactly undoes the user's mouse movement effectively making it impossible to move the mouse.

Ooookay... so I disable/enable mouse motion events before/after warping the mouse like this:

SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
SDL_WarpMouse(windowWidth/2, windowHeight/2); //center that bitch
SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);

BUT!! This is where I got a terrible slow down in events processing. Basically, it was missing entire keystrokes so some keys would report being stuck ON or key presses were missed entirely.

I just rearranged the SDL_WarpMouse to happen right after my event processing loop and this seems to have resolved the issue. But like Fingers_ I'm not happy about this. It just seems... icky.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!