Comments (17)
It's okay, you're raising valid questions here. I don't believe there is any way to "catch" a Gamepad before it's been physically disconnected. It will always be too late to do anything with a Gamepad after it's removed.
Okay, that's just a misunderstanding on my part. Thanks!
from sdl.
I'm using SDL_GetGamepadFromInstanceID
on SDL_EVENT_GAMEPAD_REMOVED
without a crash using the latest SDL3 source. Which version of SDL are you using?
I've found none of the Gamepad functions return anything useful during the SDL_EVENT_GAMEPAD_REMOVED
event. SDL_IsGamepad
even returns false (because it decides based on if the Gamepad has mapping, which will be false because the GUID is zeroed out at this point), which is very misleading - maybe this should be considered a bug at least. SDL_GetGamepadInstanceName
will return null. SDL_GetGamepadFromInstanceID
DOES work though, and returns a valid pointer.
Just to clarify: when you say crash, do you mean assertion fail?
If you've not done a SDL_OpenGamepad
, then that might be why you're getting null from SDL_GetGamepadFromInstanceID
?
So, yes, you're not opening a Gamepad. "Get the SDL_Gamepad associated with a joystick instance ID, if it has been opened." is what SDL_GetGamepadFromInstanceID
says.
from sdl.
If you've not done a SDL_OpenGamepad, then that might be why you're getting null from SDL_GetGamepadFromInstanceID?
Sorry, that was a mistake when I reduced the program from my actual program to the example code above. I am indeed calling SDL_OpenGamepad(id) in the add() function. I've updated the original example program to include this now.
Just to clarify: when you say crash, do you mean assertion fail?
Yes.
I've found none of the Gamepad functions return anything useful during the SDL_EVENT_GAMEPAD_REMOVED event. SDL_IsGamepad even returns false (because it decides based on if the Gamepad has mapping, which will be false because the GUID is zeroed out at this point), which is very misleading - maybe this should be considered a bug at least.
I'm not so familiar yet with how it's supposed to work, but yeah -- it does seem weird to me.
I'm using SDL_GetGamepadFromInstanceID on SDL_EVENT_GAMEPAD_REMOVED without a crash using the latest SDL3 source. Which version of SDL are you using?
I downloaded the latest source today from this repo, just to make sure it wasn't already fixed. Are you also running it on windows?
from sdl.
I took a video running the program -- I don't know if it provides more information than the code does, but it's here if it will help.
from sdl.
Yes, I'm on Windows 10.
SDL_IsGamepad
on an open Gamepad does return false, after SDL_EVENT_GAMEPAD_REMOVED
, which I think is kind of a bug, or misleading at worst. A Gamepad loses mapping when it's removed, so it becomes invalid for anything useful.
Moving passed "CRASH #1", can you now double-check if SDL_GetGamepadFromInstanceID
is returning null or not?
from sdl.
Moving passed "CRASH #1", can you now double-check if SDL_GetGamepadFromInstanceID is returning null or not?
Tested, and it does not return null, BUT SDL_GamepadConnected is returning false.
That's happening because it's being set to FALSE in SDL_PrivateJoystickRemoved
This happens directly from the windows event removing the controller:
from sdl.
I would expect SDL_GamepadConnected
to return false if it's been unplugged?
from sdl.
SDL_IsGamepad on an open Gamepad does return false, after SDL_EVENT_GAMEPAD_REMOVED, which I think is kind of a bug, or misleading at worst. A Gamepad loses mapping when it's removed, so it becomes invalid for anything useful.
I just wanted to respond to this, I feel like it's invalid in the sense that the way I understand it works is that I'm supposed to receive the event before the system does anything to my controller.
from sdl.
It's okay, you're raising valid questions here. I don't believe there is any way to "catch" a Gamepad before it's been physically disconnected. It will always be too late to do anything with a Gamepad after it's removed.
from sdl.
Okay, that's just a misunderstanding on my part. Thanks!
I'm glad we were able to figure it out. Do you think there is a way to clarify this for other users in the documents somewhere?
from sdl.
Okay, that's just a misunderstanding on my part. Thanks!
I'm glad we were able to figure it out. Do you think there is a way to clarify this for other users in the documents somewhere?
Yeah, I do think just adding some documentation to the event itself stating that once the event has been received by the application it has already been "disconnected." Specifically calling on SDL_GamepadConnected() on the id is either expected to return false, or undefined behavior (idk, maybe another controller gets plugged at the exact right time).
from sdl.
@slouken The only issue here is a misunderstanding of what's possible after a SDL_EVENT_GAMEPAD_REMOVED
, and that SDL_IsGamepad
always returns false after a removed Gamepad. Is this considered a bug? Shall we keep this issue open?
from sdl.
Specifically calling on SDL_GamepadConnected() on the id is either expected to return false, or undefined behavior (idk, maybe another controller gets plugged at the exact right time).
I believe the instance ID remains valid until you close the Gamepad. And I believe if the gamepad was never opened, though, then the ID will be invalid after you return from handling the removed event.
from sdl.
Specifically calling on SDL_GamepadConnected() on the id is either expected to return false, or undefined behavior (idk, maybe another controller gets plugged at the exact right time).
I believe the instance ID remains valid until you close the Gamepad. And I believe if the gamepad was never opened, though, then the ID will be invalid after you return from handling the removed event.
That's super clear. Thanks.
I would like to add, it does seem very unclear that I cannot query if a joystick ID was a gamepad in the SDL_EVENT_GAMEPAD_REMOVED
event -- I mean it's right there in the name of the event.
However it does seem a redundant to have the check in my code after discussing it with you.
from sdl.
I have a fix for SDL_IsGamepad() so it will return true even after the controller was disconnected.
With this change, if you also make the following change to your code, it will work as expected:
assert(SDL_FALSE == ::SDL_GamepadConnected(data));
from sdl.
Wow you work quick! Thanks. 👍
from sdl.
You're welcome! :)
from sdl.
Related Issues (20)
- SDL2 threading config in ./cmake/sdlchecks.cmake not correct for non-GNU compiler (e.g. SunPro cc) HOT 2
- UNIX version of SDL_GetBasePath in SDL_sysfilesystem.c not correct for Solaris, probably other UNIXes HOT 2
- Compiling SDL on SPARC platform with GNU toolset should target correct CPU by default HOT 3
- SDL incorrectly detects X11_XRANDR with CMake, does not compile on Solaris 10
- SDL build with configure (autoconf) incorrectly tries to build with Vulkan support on Solaris 10 (probably other UNIXes) HOT 11
- SDL loads wrong controller definition from gamecontrolllerdb HOT 10
- VC : Add /MT /MTd and /MD /MDd in artifacts github HOT 2
- Feature: Open SDL_StepUTF8() for public use HOT 3
- Switch SDLK_PERCENT and SDLK_DOLLAR to match ascii values? HOT 1
- KMSDRM: Garbled video with testgles2 on NVIDIA Tegra HOT 5
- doctest + SDL2main : error LNK2019 (despite using DOCTEST_CONFIG_IMPLEMENT) HOT 13
- Multiple Windows and SDL_EVENT_QUIT failure HOT 3
- SDL_RenderReadPixels doesn't give the same data depending on if the app is fullscreen or not HOT 11
- Encoding of paths in file dialogs HOT 3
- SDL_x11shape.c syntax error if SDL_X11_XSHAPE is disabled HOT 1
- segfault in testaudio HOT 2
- Issue with sdl output with AMD graphic
- Cannot create renderer even after `SDL_DestroyWindowSurface` has been called on a window HOT 3
- Implement SDL_EVENT_TEXT_EDITING_CANDIDATES for fcitx and ibus IMEs
- SDL3 key questions HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdl.