Hello Guest

[BUG] LWJGL 2.2.0 build #234 Mouse up reported twice

  • 6 Replies
  • 17002 Views
[BUG] LWJGL 2.2.0 build #234 Mouse up reported twice
« on: September 18, 2009, 19:59:45 »
Code: [Select]
while (!  Display.isCloseRequested()  ) {
    ...
    while (  Mouse.next()  ) {
        ...
        if (  ( Mouse.getEventButton() != -1 ) && ( Mouse.getEventButtonState() == false )  ) {
            // Happily acquired a mouse up event.
    ...
    Display.update();
    ...

Wrong. With v2.2.0 build #234 I get the mouse up event twice. I get it only once as I should with "stable" v2.1.0.
I am sorry if I glued the posted example together incorrectly. The point goes through, and that's what matters. I think.

*

Offline Matzon

  • *****
  • 2242
Re: [BUG] LWJGL 2.2.0 build #234 Mouse up reported twice
« Reply #1 on: September 19, 2009, 06:30:10 »
have you seen it between 2.1 and 2.2#234 ? - just to narrow the search down ..

Re: [BUG] LWJGL 2.2.0 build #234 Mouse up reported twice
« Reply #2 on: September 19, 2009, 12:19:56 »
The first build from https://www.newdawnsoftware.com/hudson/view/LWJGL/ that I tested was #222.

It seems to be a Windows-only issue. And on top of that, it happens only when the mouse is not grabbed. Fullscreen or not, makes no difference (though in Linux I could not get to fullscreen, but that's another story).

Report of tests:
Code: [Select]
two windows xp machines:
v2.1.0
grabbed: mouse up reported ONCE
not grabbed: mouse up reported ONCE

v2.2.0 #222
grabbed: mouse up reported ONCE
not grabbed: mouse up reported TWICE

v2.2.0 #235
grabbed: mouse up reported ONCE
not grabbed: mouse up reported TWICE

one linux machine:
v2.1.0
grabbed: mouse up reported ONCE
not grabbed: mouse up reported ONCE

v2.2.0 #222
grabbed: mouse up reported ONCE
not grabbed: mouse up reported ONCE

v2.2.0 #235
grabbed: mouse up reported ONCE
not grabbed: mouse up reported ONCE

The code I used to test:
Code: [Select]
package gima.apps.tests;

import java.util.Random;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;


public class MouseUpTwice {

public static void main( String[] args ) {
boolean isFullscreen=false, isGrabbed=false; int width=800, height=600, bppMin=24;
if ( args.length >= 1 ) if (  args[0].equals("true" )  ) isFullscreen = true;
if ( args.length >= 2 ) if (  args[1].equals( "true" )  ) isGrabbed = true;
if ( args.length >= 3 ) width = Integer.parseInt( args[2] );
if ( args.length >= 4 ) height = Integer.parseInt( args[3] );
if ( args.length >= 5 ) bppMin = Integer.parseInt( args[4] );
new MouseUpTwice( isFullscreen, isGrabbed, width, height, bppMin );
}

public MouseUpTwice( boolean isFullscreen, boolean isGrabbed, int width, int height, int bppMin ) {
System.out.println(  String.format( "Fullscreen: %b, Grabbed: %b, Width: %d, Height: %d, BPPMin: %d", isFullscreen, isGrabbed, width, height, bppMin )  );
try {
DisplayMode foundDM = null;
for (  DisplayMode dm : Display.getAvailableDisplayModes()  ) { if ( dm.getBitsPerPixel() >= bppMin ) if ( dm.getFrequency() >= 60 ) if ( dm.getWidth() == width ) if ( dm.getHeight() == height ) {
foundDM = dm;
break;
} }
if ( foundDM == null ) foundDM = new DisplayMode( width, height );
Display.setDisplayMode( foundDM );
Display.setFullscreen( isFullscreen );
Mouse.setGrabbed( isGrabbed );
Display.create();
}
catch ( LWJGLException e ) {  e.printStackTrace();  }


while (!  Display.isCloseRequested()  ) {
while (  Mouse.next()  ) {
if (  ( Mouse.getEventButton() != -1 ) && ( Mouse.getEventButtonState() == false )  ) {
/*
*  Mouse up event
*  Random, because it is easier to distinguish when few events come up very quickly
*/

String rand = String.valueOf(  new Random().nextBoolean()  ).replace( "true", "gecko" );
rand = String.valueOf(  rand.replace( "false", "canine" )  );
System.out.println(  "Mouse up .. " +  rand );
}
}
Display.update();
try {  Thread.sleep( 10 );  } catch (  InterruptedException e )  {}
}

}
}[CODE]
[/code]

Re: [BUG] LWJGL 2.2.0 build #234 Mouse up reported twice
« Reply #3 on: September 19, 2009, 22:28:39 »
A random boolean to distinguish multiple events? Renamed to gecko and canine? I hope I won't wake up tomorrow and realise I just dreamt stuff up in a state of sleep deprivation ;D

Anyway, I tried this on Windows XP 32 bit with LWJGL 2.2.0 #235 and can confirm this.

It happens if you drag the mouse after pushing the button down and before releasing (inside or outside the window) it again. It does not happen if you do not move the cursor between pushing the button down and releasing it again.

(though in Linux I could not get to fullscreen, but that's another story).

That's because of your if if (dm.getFrequency() >= 60) {. Display modes on Linux report weird/wrong values, like 0, 51, 52, etc. Thus this if ignores most if not all display modes.
« Last Edit: September 19, 2009, 22:56:07 by Ciardhubh »

Re: [BUG] LWJGL 2.2.0 build #234 Mouse up reported twice
« Reply #4 on: September 20, 2009, 00:20:05 »

A random boolean to distinguish multiple events? Renamed to gecko and canine? I hope I won't wake up tomorrow and realise I just dreamt stuff up in a state of sleep deprivation ;D
Aww, I though it would be cute :P Besides, having them grow by the numbers would be too dry.


Anyway, I tried this on Windows XP 32 bit with LWJGL 2.2.0 #235 and can confirm this.


It happens if you drag the mouse after pushing the button down and before releasing (inside or outside the window) it again. It does not happen if you do not move the cursor between pushing the button down and releasing it again.
Eep. Forgot to mention that.


(though in Linux I could not get to fullscreen, but that's another story).

That's because of your if if (dm.getFrequency() >= 60) {. Display modes on Linux report weird/wrong values, like 0, 51, 52, etc. Thus this if ignores most if not all display modes.
Oh, good to know. Thanks.


Re: [BUG] LWJGL 2.2.0 build #234 Mouse up reported twice
« Reply #5 on: January 07, 2011, 02:34:54 »
What is happening I think is that the mousemoves are causing mouse events too, and getmouseventstate is not enough to differentiate the two.

It is possible, though reeks of hackiness, but does seem to work on linux, today, with the sun shining, to test for dx and dy, and signal a mouseup if they're both 0:

Code: [Select]
while( Mouse.next() ) {
if( Mouse.getEventButtonState() ) {
System.out.println("mouse click" );
} else if( Mouse.getEventDX() == 0 && Mouse.getEventDY() == 0) {
System.out.println("mouse up" );
}
}


Re: [BUG] LWJGL 2.2.0 build #234 Mouse up reported twice
« Reply #6 on: January 07, 2011, 09:37:47 »
First you need to check Mouse.getEventButton() >= 0 and only then check the Mouse.getEventButtonState().

And always upgrade to the latest LWJGL version.