Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controllers stops working after screen mode changes #4723

Closed
w0615 opened this issue Apr 27, 2017 · 6 comments
Closed

Controllers stops working after screen mode changes #4723

w0615 opened this issue Apr 27, 2017 · 6 comments

Comments

@w0615
Copy link

w0615 commented Apr 27, 2017

Hello.
i am trying to add gamepad support to my libgdx game and i am hacing a issue when the display mode changes (window to fullscreen or fullscreen to window)

the gamepad stops working after settings are updated

Controller devices: Xbox 360 Wired Controller for Windows, Eurocase EUGA-58,
Platform: Desktop (Windows 10 Pro 64 bits)
libGDX version: 1.9.5, 1.9.6 and 1.9.7-SNAPSHOT 26/4/2017 (all versions have the same problem)
eyes of light 26_4_2017 20_05_43

@Zomby2D
Copy link
Contributor

Zomby2D commented Apr 27, 2017

I'm unable to reproduce this. I've tested with both lwjgl and lwjgl3 backends and my controllers keep working when I change the display mode. (I'm also on Windows 10 Pro x64)

Could you please provide an executable example?

@w0615
Copy link
Author

w0615 commented Apr 27, 2017

I did some test and i have more info

the problem comes whe i set the controllerlistener for expecific gamepad
using the Controller.addListener method

When i add the listener using Controllers.addListener all works fine

`
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics.DisplayMode;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.ControllerAdapter;
import com.badlogic.gdx.controllers.Controllers;
import com.badlogic.gdx.controllers.PovDirection;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;

public class testGame extends ApplicationAdapter {
ShapeRenderer SR;
float X = 320;
float Y = 240;
@OverRide
public void create () {
SR = new ShapeRenderer();
SR.setColor(Color.WHITE);
SR.setAutoShapeType(true);

	//Hello
	
	
	//1- paste one of the put_me methods
	
	
	//2- test gamepad using Pov directions or sticks
	//press F1 for fullscreen
	//press F2 for windowed screen
	

}

@Override
public void render () {
	keyEvent(Input.Keys.F1, true);
	keyEvent(Input.Keys.F2, false);
	Gdx.gl.glClearColor(0, 0, 0, 1);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	SR.begin();
	SR.rect(X,Y,64,64);
	SR.end();
}

@Override
public void dispose () {

}
public void Put_me_on_create_method_i_will_bug_your_gamepad_after_screen_mode_changes(){
	Controllers.getControllers().first().addListener(new ControllerTest());
}
public void Put_me_on_create_method_i_will_work_fine(){
	Controllers.addListener(new ControllerTest());
}
public void keyEvent(int keycode, boolean fullscreen){
	if (Gdx.input.isKeyJustPressed(keycode)) {
		setDisplay(fullscreen);
	}
}
public void setDisplay(boolean fullscreen){
	if (fullscreen) {
		DisplayMode displayMode = Gdx.graphics.getDisplayMode(Gdx.graphics.getMonitor());
		if(!Gdx.graphics.setFullscreenMode(displayMode)) {
		   //switching to full-screen mode failed
		}
	}else{
		Gdx.graphics.setWindowedMode(640, 480);
	}
}

//ontroller manager
class ControllerTest extends ControllerAdapter{
	public boolean povMoved(Controller controller, int povIndex, PovDirection value) {
		if (value == PovDirection.north) {
			Y+=14;
		}
		if (value == PovDirection.south) {
			Y-=14;
		}
		return super.povMoved(controller, povIndex, value);
	}
	@Override
	public boolean axisMoved(Controller controller, int axisIndex, float value) {
		if (value > 0) {
			X += 14;
		}
		if (value < 0) {
			X -= 14;
		}
		return super.axisMoved(controller, axisIndex, value);
	}
}

}`

@Zomby2D
Copy link
Contributor

Zomby2D commented Apr 27, 2017

I understand what's going on now.

Ois requires the window handle so when that changes, a new instance of Ois is created. Because of that, the controllers array ends up getting cleared and re-populated. The listener attached to the "old" controller is not transferred to the "new" one.

@intrigus
Copy link
Contributor

This has been fixed by #4743, right?

@Tom-Ski Tom-Ski closed this as completed Jun 25, 2017
@Tom-Ski
Copy link
Member

Tom-Ski commented Jun 25, 2017

Yes, thanks @intrigus

@electronstudio
Copy link

This is only partially fixed. Event based listeners continue to work, yes, but polling the controller stops working after the screen mode changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants