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

Started by gima, September 18, 2009, 19:59:45

Previous topic - Next topic

gima

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.

Matzon

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

gima

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:
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:
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]

Ciardhubh

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.

Quote from: hanrock on September 19, 2009, 12:19:56
(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.

gima


Quote from: Ciardhubh 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
Aww, I though it would be cute :P Besides, having them grow by the numbers would be too dry.


Quote from: Ciardhubh on September 19, 2009, 22:28:39
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.


Quote from: Ciardhubh on September 19, 2009, 22:28:39
Quote from: hanrock on September 19, 2009, 12:19:56
(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.


hughperkins

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:

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



Matthias

First you need to check Mouse.getEventButton() >= 0 and only then check the Mouse.getEventButtonState().

And always upgrade to the latest LWJGL version.