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

Updated more functions to use SDL_GetStringRule #10311

Merged
merged 29 commits into from
Jul 19, 2024

Conversation

slouken
Copy link
Collaborator

@slouken slouken commented Jul 18, 2024

Fixes #10300

  • SDL_GetAudioPlaybackDevices()
  • SDL_GetAudioRecordingDevices()
  • SDL_GetCameraSupportedFormats()
  • SDL_GetCameras()
  • SDL_GetDisplays()
  • SDL_GetFullscreenDisplayModes()
  • SDL_GetGamepads()
  • SDL_GetHaptics()
  • SDL_GetJoysticks()
  • SDL_GetKeyboards()
  • SDL_GetMice()
  • SDL_GetPreferredLocales()
  • SDL_GetSensors()
  • SDL_GetTouchDevices()
  • SDL_GetWindowICCProfile()
  • SDL_GetWindows()

@slouken slouken requested a review from icculus July 18, 2024 16:47
@slouken slouken marked this pull request as draft July 18, 2024 16:47
@slouken slouken force-pushed the const-devices branch 6 times, most recently from cb1b93f to 11ff4dc Compare July 18, 2024 22:27
@slouken
Copy link
Collaborator Author

slouken commented Jul 18, 2024

@icculus, I made it possible to free specific pointers with SDL_FreeEventMemory(), which some applications will want to do for more fine grained memory management.

@slouken slouken force-pushed the const-devices branch 2 times, most recently from f3a2cc2 to 1b68065 Compare July 18, 2024 22:38
Also clarify in the documentation that you should not call SDL_FreeEventMemory(NULL) from your main thread.
@slouken slouken force-pushed the const-devices branch 8 times, most recently from a9d895d to 2d81f99 Compare July 19, 2024 01:12
This allows threads to free memory from their local pool without affecting events that are queued, and to transfer memory ownership cleanly between threads that are queuing and dequeuing events.
This prevents race conditions where calling an API from one thread returns the data and it's freed by updates on another thread
@slouken slouken marked this pull request as ready for review July 19, 2024 07:22
@slouken
Copy link
Collaborator Author

slouken commented Jul 19, 2024

@sezero, I will have an sdl2-compat update ready soon.

Copy link
Collaborator

@icculus icculus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. I think what prompted my "are we being too clever?" comment before was the actual presence of a "rule" ...because this is exactly the sort of thing that made, say, Objective-C memory management a nightmare. You had to know the rules which were special and magical and tucked away in a different chapter of the manual and had 20 exceptions.

No formal rule, just a single line of text in these functions that says "this is temporary memory that will be free'd later, but you can claim it now with ClaimMemory"? Honestly, it makes me feel like we aren't accidentally driving over a cliff now.

Clever, in a good way! :)

@icculus
Copy link
Collaborator

icculus commented Jul 19, 2024

Once this merges, in addition to the sdl2-compat stuff, though, someone should delete SDL3/SDL_GetStringRule.md from the wiki.

@slouken
Copy link
Collaborator Author

slouken commented Jul 19, 2024

Once this merges, in addition to the sdl2-compat stuff, though, someone should delete SDL3/SDL_GetStringRule.md from the wiki.

Sure, I'll do that.

@slouken slouken merged commit a340de6 into libsdl-org:main Jul 19, 2024
39 checks passed
@slouken slouken deleted the const-devices branch July 19, 2024 19:22
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

Successfully merging this pull request may close these issues.

SDL_GetStringRule for SDL_GetJoysticks(), etc.?
2 participants