We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2738 - [patch] (OSX) Removed joysticks wrongly marked as closed.
Summary: [patch] (OSX) Removed joysticks wrongly marked as closed.
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: HG 2.0
Hardware: x86 Mac OS X (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: triage-2.0.4
Depends on:
Blocks:
 
Reported: 2014-09-23 07:47 UTC by Rodrigo Cardoso
Modified: 2015-03-24 17:55 UTC (History)
2 users (show)

See Also:


Attachments
patch that fixes the issue (397 bytes, patch)
2014-09-23 07:47 UTC, Rodrigo Cardoso
Details | Diff
new patch (998 bytes, patch)
2014-09-23 08:12 UTC, Rodrigo Cardoso
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rodrigo Cardoso 2014-09-23 07:47:26 UTC
Created attachment 1878 [details]
patch that fixes the issue

I noticed that when you remove a joystick in cocoa, SDL marked it as closed internally even if it is not!

This caused an annoying issue that prevented the Joystick ID from being retrieved before closing it.

There is an one line patch attached that fixes the issue.
Comment 1 Rodrigo Cardoso 2014-09-23 08:12:36 UTC
Created attachment 1879 [details]
new patch

right after submitting the bug I noticed I was not getting the "release all buttons and center all axes" events that should be fired when removing a device, the new patch takes that into account.

notice that I left "joystick->closed" in the if even not relying in it anymore because I dont know if other platforms need it, just put an OR there.
Comment 2 Rodrigo Cardoso 2014-10-07 19:39:03 UTC
Just some more info on why I found this.

First I noticed that sometimes I was not getting the "release all buttons and center all axes" sometimes, and I was also trying to understand the purpose of SDL_JoystickGetAttached in the examples, since the joystick was invalidated before I get a change to get its instance ID and/or close it (at last on mac).

Preventing SDL to flag the joystick as 'closed' early fixed this problem.

After making this change, I was able to retrieve the instanceID correctly, so I could compare with the "which" field of the SDL_JOYDEVICEREMOVED event and close the joystick as I should, without keeping another copy of the instance id, and still got the release button events after that as I expected.

Also, as far as I understand only SDL_SYS_JoystickClose should change the ->closed to 1, right?

bye
Comment 3 Ryan C. Gordon 2015-02-19 05:22:22 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 4 Ryan C. Gordon 2015-03-24 01:16:52 UTC
(In reply to Rodrigo Cardoso from comment #2)
> Also, as far as I understand only SDL_SYS_JoystickClose should change the
> ->closed to 1, right?

This appears to be true, and it looks like the Windows code has the same problem. I'll check this soon.

--ryan.
Comment 5 Ryan C. Gordon 2015-03-24 17:55:28 UTC
I ended up cleaning up a bunch of stuff in the joystick subsystem while trying to understand when and why we should be setting that "closed" flag. I ended up removing it altogether.  :)

In addition to other improvements, this specific bug is now fixed in https://hg.libsdl.org/SDL/rev/bd062398b648, thanks!

--ryan.