Secretchronicles / TSC

An open source two-dimensional platform game.
https://secretchronicles.org/
GNU General Public License v3.0
205 stars 49 forks source link

Game Controller State Only Detected At Game Startup, Seg Fault Possible... #608

Closed datahead8888 closed 6 years ago

datahead8888 commented 7 years ago

If you connect a game controller while playing TSC, it will not be detected in the menu until you restart the game executable. It does, however, let the player face left and right and/or move when starting a level. If you disconnect a game controller while playing TSC, then select "None" then "No Joystick" in the menu back and forth some times, the game segfaults.

It probably just needs to call cJoystick::Init() again at the appropriate place to run the SFML joystick detection logic, at least when the menus show up. It probably does not make sense repeatedly to call Joystick detection logic again and again during the main game loop, but I am open to other ideas.

I would consider the connection behavior a bug, as the menus should show the correct joystick connection state when accessed; players might want to connect a controller after starting the game. The seg fault is clearly a bug regardless.

xet7 commented 7 years ago

I am able to duplicate this.

I did try to add

void cJoystick::Init();

to tsc/src/core/main.cpp but did not get that syntax working correctly, and places where I added code (when it did compile) did not have any effect to the bug.

xet7 commented 7 years ago

On Ubuntu 17.10 SMFL version is 2.4.2 and joystick documentation is here

datahead8888 commented 7 years ago

but did not get that syntax working correctly

Could you post the syntax error you got?

Otherwise, if you post your code in a branch, I could try to take a quick look at the compilation issue when I get a chance. It might go a bit slowly, though.

refi64 commented 6 years ago

Hoping to tackle this soon...I mean, how hard could it be?

(Please don't answer that.)

refi64 commented 6 years ago

I was about to say we can just re-init while polling for events, but there are apparently several places in the source code that discard any input events. Beautiful :ok_hand:.

refi64 commented 6 years ago

I have a potential fix for this in the joy branch, but my controller seems to either have broken or my drivers screwed up. If anyone can test it out, that would be great!!

Quintus commented 6 years ago

I merged your joy branch with commit a7c5aee7142d8e7de1a75ed6a0fa306d2f483fdb (untested). Comment if something breaks.

datahead8888 commented 4 years ago

If a player connects a controller while playing, it should probably autoselect it if none is selected. Otherwise it's a bit tedious to go into the options menu and activate it.

Quintus commented 4 years ago

Am 16. Mai 2020 um 21:18 Uhr -0700 schrieb Chris Jacobsen:

If a player connects a controller while playing, it should probably autoselect it if none is selected. Otherwise it's a bit tedious to go into the options menu and activate it.

I do not think this is possible. SFML does not issue an event for the connection of a controller.

-quintus

-- Blog: https://mg.guelker.eu

refi64 commented 4 years ago

udev can be monitored for this on Linux, though I'm not sure about other platforms & it's not something that's supported on Flatpak since udev's protocol is not stable.

On Sun, May 17, 2020, 2:34 AM Marvin Gülker notifications@github.com wrote:

Am 16. Mai 2020 um 21:18 Uhr -0700 schrieb Chris Jacobsen:

If a player connects a controller while playing, it should probably autoselect it if none is selected. Otherwise it's a bit tedious to go into the options menu and activate it.

I do not think this is possible. SFML does not issue an event for the connection of a controller.

-quintus

-- Blog: https://mg.guelker.eu

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/Secretchronicles/TSC/issues/608#issuecomment-629756388, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM4YSI27MLCUGUIC7HWC6DRR6HPBANCNFSM4DG6HMVQ .

Quintus commented 4 years ago

One could of course just poll the controller configuration via SFML again. That should work.