Advertisement

SDL_WM_GrabInput locks up mouse.

Started by August 03, 2011 08:02 PM
0 comments, last by dandrestor 13 years, 1 month ago
I'm implementing camera rotation on my application. To allow the user to freely rotate the camera outside of the window bounds, I use SDL_WM_GrabInput.

It seems to work correctly. However, after the user stops holding the button (i.e. I recieve SDL_MOUSEBUTTONUP), the next mouse click doesn't work. For that click, I don't receive a SDL_MOUSEBUTTONDOWN, but I receive a SDL_MOUSEBUTTONUP. It doesn't matter if I click inside or outside of the application, the next mouse click just doesn't work. It starts working after that click, however.

My setup is a bit uncommon (Linux, D programming language + Derelict binding), but I don't think that's causing the problem.

Here's my main loop:

/// Start the rendering loop.
void display()
{
bool cameraMode = false;
while (true)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_MOUSEBUTTONDOWN:
writeln("down");
if (event.button.button & SDL_BUTTON(SDL_BUTTON_LEFT))
{
// Start camera rotation mode
cameraMode = true;
SDL_ShowCursor(0);
SDL_WM_GrabInput(SDL_GRAB_ON);

}
break;

case SDL_MOUSEBUTTONUP:
writeln("up");
if (event.button.button & SDL_BUTTON(SDL_BUTTON_LEFT))
{
// End camera rotation mode
cameraMode = false;
SDL_ShowCursor(1);
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
break;

case SDL_MOUSEMOTION:
if (cameraMode == true)
{
rotationX += cast(double)event.motion.xrel / 10.0;
rotationY += cast(double)event.motion.yrel / 10.0;
reconfigureView();
}
break;

case SDL_QUIT:
return;

default:
break;
}
}

render();
}
}


Here's a sample console output (repeatedly trying to move the camera):


down
up
up
down
up
up
down
up
up
down
up
up
down
up
up
down
up
up
...


Edit: Sorry for the bad title, I forgot
Hi, I'm having the exact same problem. I was wondering, did you solve it, in the meantime?

Thanks,
D.

This topic is closed to new replies.

Advertisement