I am currently getting some weird problems with GLFW:
Sometimes the mouse position changes for 200 pixels (horizontal, vertically it's something else, see below) in one frame. Sometimes it then even changes back and forth again. This only seems to happen with low frame rates, and probably only affects the X11 code as noone else currently has seen it here.
This is where I inserted debug printfs into glfw:
Code:
diff --git a/Horde3D/Dependencies/Source/glfw/x11/x11_window.c b/Horde3D/Dependencies/Source/glfw/x11/x11_window.c
--- a/Horde3D/Dependencies/Source/glfw/x11/x11_window.c
+++ b/Horde3D/Dependencies/Source/glfw/x11/x11_window.c
@@ -519,6 +519,7 @@
{
if( _glfwWin.MouseLock )
{
+ printf("1 (%d, %d): ", event.xmotion.x, event.xmotion.y);
_glfwInput.MousePosX += event.xmotion.x -
_glfwInput.CursorPosX;
_glfwInput.MousePosY += event.xmotion.y -
@@ -526,9 +527,12 @@
}
else
{
+ printf("2: ");
_glfwInput.MousePosX = event.xmotion.x;
_glfwInput.MousePosY = event.xmotion.y;
}
+ printf("Mouse movement: %d/%d\n", _glfwInput.MousePosX, _glfwInput.MousePosY);
_glfwInput.CursorPosX = event.xmotion.x;
_glfwInput.CursorPosY = event.xmotion.y;
_glfwInput.MouseMoved = GL_TRUE;
@@ -1538,6 +1542,8 @@
// is not used, so I decided to use it.
//XSync( _glfwLibrary.display, False );
+ printf("Events:\n");
+
// Empty the window event queue
while( XPending( _glfwLibrary.display ) )
{
@@ -1562,6 +1568,7 @@
if(_glfwInput.CursorPosX < minx || _glfwInput.CursorPosX > maxx ||
_glfwInput.CursorPosY < miny || _glfwInput.CursorPosY > maxy)
{
+ printf("Resetting mouse.\n");
// Move the mouse pointer back to the window center so that it
// does not wander off...
_glfwPlatformSetMouseCursorPos( _glfwWin.Width/2,
( Patch shortened a bit so it maybe won't apply)
What these changes print are 1) the position data I get from X11 (event.xmotion.x) and 2) the data glfw stores internally (_glfwInput.MousePosX).
This is what GLFW outputs with my changes:
Quote:
Events:
1 (201, 290): Mouse movement: -199/-10
1 (199, 290): Mouse movement: -201/-10
Resetting mouse.
Events:
1 (197, 290): Mouse movement: -404/-20
Resetting mouse.
Events:
1 (399, 300): Mouse movement: -405/-20
1 (397, 300): Mouse movement: -407/-20
This is what I think happens:
First, the cursor leaves the area glfw wants it in (for a 800x600 window the 400x300 center, therefore x = 200). GLFW now sets the mouse position back to the center and changes the internal variables. Now a X11 event is received though which still contains the old position as it probably was issued before the change. GLFW now compares it with the internal value and thinks, hey, the mouse just moved 200 pixels to the left. It of course adjusts the mouse position again (because it thinks the mouse is out of the center area), but this time everything will work well because of the large difference between the next event and the first time changing the mouse position.
Anybody has ever met that issue? Anyone knows how this could be fixed?
EDIT: Huh. Reenabling the XSync over the printf("Events:\n"); seems to have fixed it. Weird.