LWJGL
May 24, 2013, 05:31:46 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: [BUG] LWJGL 2.2.0 build #234 Mouse up reported twice  (Read 3511 times)
gima
Newbie
*
Posts: 8


« on: September 18, 2009, 12:59:45 »

Code:
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.
Logged
Matzon
Administrator
Demigod
*****
Posts: 2239



« Reply #1 on: September 18, 2009, 23:30:10 »

have you seen it between 2.1 and 2.2#234 ? - just to narrow the search down ..
Logged

gima
Newbie
*
Posts: 8


« Reply #2 on: September 19, 2009, 05: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:
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:
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]
Logged
Ciardhubh
Talks Too Much
***
Posts: 159


« Reply #3 on: September 19, 2009, 15: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 Grin

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.
Logged
gima
Newbie
*
Posts: 8


« Reply #4 on: September 19, 2009, 17: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.

Logged
hughperkins
Newbie
*
Posts: 2


« Reply #5 on: January 06, 2011, 18: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:
while( Mouse.next() ) {
if( Mouse.getEventButtonState() ) {
System.out.println("mouse click" );
} else if( Mouse.getEventDX() == 0 && Mouse.getEventDY() == 0) {
System.out.println("mouse up" );
}
}

Logged
Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #6 on: January 07, 2011, 01: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.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!