Commit Graph

14895 Commits (fc7afa9cbf400d270f33a8eda5483825f323510e)

Author SHA1 Message Date
ilyas-taouaou d0d8b28df1 Change SDL_Vulkan_GetInstanceExtensions 2023-11-02 14:27:36 -04:00
Ozkan Sezer 338974bb29 SDL_test_memory.c: fix build against older windows SDKs. 2023-11-02 21:00:02 +03:00
Sam Lantinga 618d15bce6 Fixed typo 2023-11-02 10:33:44 -07:00
Sam Lantinga ad0af48883 Check to make sure the Windows joystick device has buttons and axes
This reverts commit e5a15f94e2.

It turns out removing this check allows mice like the ROG PUGIO II to show up as game controllers. We need to find a different way to differentiate between gaming mice and pedals.

Since these mice show up as controllers, and potentially causing games to use them instead of real controllers, we'll go ahead revert this change for now.

Reopens https://github.com/libsdl-org/SDL/issues/8227
2023-11-02 08:33:15 -07:00
Ryan C. Gordon ac6b32bb02
gendynapi.py: Discard SDLMAIN_DECLSPEC functions.
Otherwise SDL_main and SDL_App* functions look like exported symbols instead
of functions the app is meant to implement.

Reference PR #8247.
2023-11-01 21:47:42 -04:00
Ryan C. Gordon 9c664b0062
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:

First:

    int SDL_AppInit(int argc, char **argv);

This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.

Then:

     int SDL_AppIterate(void);

This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).

Next:

    int SDL_AppEvent(const SDL_Event *event);

This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.

Finally:

    void SDL_AppQuit(void);

This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.

The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.

In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.

On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).

Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.

The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.

Fixes #6785.
Reference PR #8247.
2023-11-01 18:40:41 -04:00
Sam Lantinga 9323417e9c Fixed gendyapi.py parsing of SDL_RELEASE_GENERIC 2023-11-01 08:36:51 -07:00
Ryan C. Gordon 759cdf6159
audio: Fixed GetFirstAudioDeviceAdded().
It forgot to check for the type of device needed.
2023-11-01 00:39:51 -04:00
Ryan C. Gordon 0e614d9179
audio: Massive reworking on thread locking.
This cleans up a ton of race conditions, and starts moving towards something
we can use with Clang's -Wthread-safety (but that has a ways to go still).
2023-11-01 00:10:25 -04:00
Ryan C. Gordon 40fb76196c
audio: Don't let simplified audio streams bind to new devices.
This can happen if you close the stream's underlying device directly, which
removes the binding but doesn't destroy the object.

In this case, the stream remains valid until destroyed, but still should not
be able to be bound to a new device.
2023-10-31 10:52:50 -04:00
Ryan C. Gordon 24e3328cca
audio: Don't reset device ID counter on subsystem init/quit.
Otherwise you risk a buggy app holding an obsolete device ID that now refers
to a different device after reinit.
2023-10-31 10:50:37 -04:00
Anonymous Maarten 5d95cbde37 cmake: reset check state before testing -fobjc-arc 2023-10-30 21:14:39 +01:00
Anonymous Maarten f18120c83c cmake: check -fobjc-arc compiler flag on Apple platforms 2023-10-30 19:59:28 +01:00
Anonymous Maarten 4aacc4b92e cmake: file(RELATIVE_PATH) needs 2 absolute paths 2023-10-30 19:50:35 +01:00
Ryan C. Gordon dcc8805c21
testaudio: Fixed compiler warning on Visual Studio. 2023-10-30 13:09:56 -04:00
Ryan C. Gordon 9cb259e865
audio: Never SDL_PushEvent from anywhere but SDL_UpdateAudio().
Fixes some corner-case deadlocks.
2023-10-30 13:08:10 -04:00
Frank Praznik 875e45e70b wayland: Sanity check pointers and protocols before confining 2023-10-29 14:24:47 -04:00
Frank Praznik 0e87b71d08 wayland: Check the relative pointer handle before destroying
If the relative protocol is unsupported, this will always be null and the destroy function won't be called.
2023-10-29 14:15:23 -04:00
Anonymous Maarten 6127ac0871 Use SDL_DISABLE_ALLOCA instead of HAVE_ALLOCA in SDL_stdinc.h 2023-10-28 18:54:12 +02:00
Sam Lantinga 552bee47cb Clear any previous errors if we successfully show a message box 2023-10-27 10:11:23 -07:00
Sam Lantinga 343da852a6 Don't try to use the Wayland messagebox if we're not in Wayland
Also cleaned up some potential file handle leaks when querying the zenity version
2023-10-27 10:11:23 -07:00
Ryan C. Gordon f63e9a8a3f
wasapi: Handle disconnected devices that get reconnected.
The device ID strings don't change between connects, so we need to move the
old device object out of the way if it still exists as a zombie, and let
the reconnected device get itself a fresh object.
2023-10-27 01:30:27 -04:00
Ryan C. Gordon 5fa7b291d4
wasapi: Fixed memory leak if new audio devices fail to add. 2023-10-27 01:30:13 -04:00
Ryan C. Gordon 468c386686
wasapi: Handle disconnect notifications from the management thread, too.
These are also pretty heavyweight, don't do them from the notification
thread, which can deadlock everything.
2023-10-27 01:28:51 -04:00
Ryan C. Gordon ce3be02b48
wasapi: If device is marked as a zombie, don't try to resuscitate it. 2023-10-27 01:27:22 -04:00
Ryan C. Gordon 85923049a6
wasapi: Patched to compile. 2023-10-26 23:09:11 -04:00
Ryan C. Gordon 9bec57309c
wasapi: Proxy default device change handling to management thread.
This does a ton of work that can deadlock, because several crucial WASAPI
things that we want to do in response to this will block until the
notification callback has returned, so we can't call them from the handler
directly, or we'll be waiting until the thing that called us returns.
2023-10-26 23:03:27 -04:00
Ryan C. Gordon c45b5121ce
audio: Fixed potential race condition.
We need to check if the device is ready to close before releasing the lock,
in case other things are messing with the list of logical devices.
2023-10-26 23:03:27 -04:00
Sam Lantinga 8b6da3c701 Fixed making the EGL context current when resuming on Android
Make sure that we don't have the context cached as current on the current thread.
2023-10-26 17:07:40 -07:00
SDL Wiki Bot 2e9eb1073d Sync SDL3 wiki -> header 2023-10-26 18:23:13 +00:00
Ryan C. Gordon e6116d399a
mutex: Removed SDL_MUTEX_MAXWAIT.
Fixes #8436.
2023-10-26 14:21:53 -04:00
SDL Wiki Bot 82f48be3ef Sync SDL3 wiki -> header 2023-10-26 12:58:14 +00:00
Ryan C. Gordon 899eb0d042 thread: Locking mutexes and rwlocks are now void functions.
Almost nothing checks these return values, and there's no reason a valid
lock should fail to operate. The cases where a lock isn't valid (it's a
bogus pointer, it was previously destroyed, a thread is unlocking a lock it
doesn't own, etc) are undefined behavior and always were, and should be
treated as an application bug.

Reference Issue #8096.
2023-10-26 08:57:34 -04:00
Frank Praznik 082ef41566 alsa: Fix crash from invalid handle pointer
ALSA expects handles to be of type ALSA_Device, and passing the handle for the default device as a plain string causes a crash as it attempts to deference the string contents itself as a pointer to a string.

Create immutable static ALSA_Device structs for the default devices and pass those as the handles. They are not placed in the hotplug list, and the audio layer doesn't attempt to free ALSA handles, so there is no need to worry about them being erroneously freed.
2023-10-25 19:37:43 -04:00
Ozkan Sezer a9aa15c792 CI: change FreeBSD CI runner to cross-platform-actions. 2023-10-26 01:03:40 +03:00
Sam Lantinga 23ceae94c9 Fixed Xbox 360 Controller support using libusb on Linux 2023-10-25 14:50:07 -07:00
Ryan C. Gordon ace0c2c297
mutex: Fixed bug where generic SDL_TryLockMutex would incorrectly block.
Fixes #8433.
2023-10-25 13:03:46 -04:00
Sam Lantinga f52b330ed8 Added support for the HP HyperX Clutch Gladiate controller 2023-10-25 09:00:26 -07:00
Ryan C. Gordon b61706373c
n3ds: Check that audio thread name starts with "SDLAudioP"
The string has a number after it, so a basic SDL_strcmp() will never match.

Reference PR #8346.

(cherry picked from commit cba6090398f581415938aa53c232142c85d23009)
2023-10-24 23:58:30 -04:00
ds-sloth 6827b3331d
n3ds systhread - use 80kb thread stack size as default, remove hard cap
(cherry picked from commit 3823ba1ded857a8af52d765b2d3ae6641b15dfe1)
2023-10-24 23:57:12 -04:00
ds-sloth e4cd1d4059
n3ds systhread - prefer to put audio thread on system core
(cherry picked from commit 301ee21f33c7e2cef4a0c484640fb028378a2fc5)
2023-10-24 23:56:34 -04:00
ds-sloth 1023d8ec84
SDL_n3dsaudio.c - don't risk leaving current_priority uninitialized
(cherry picked from commit 6623c87d0b7f6bae2ac16991aea53551899481b9)
2023-10-24 23:48:53 -04:00
ds-sloth 07171be596
SDL_n3dsaudio.h: use triple buffering
(cherry picked from commit 070f57820f401cb962e743bb3a4d12e346d6ed4b)
2023-10-24 23:48:17 -04:00
ds-sloth 6efe957159
SDL_n3dsaudio.c: separate mixer locks from audio device locks
(cherry picked from commit 62266dbd4fa79090025317a71473eb764b2e1abe)

(SDL3 audio backends don't have the LockDevice interfaces, so this just
ended up being a comment.)
2023-10-24 23:47:13 -04:00
Sam Lantinga 39a961ba41 Added support for "%[]" sscanf syntax
Fixes https://github.com/libsdl-org/SDL/issues/8423
2023-10-24 17:28:15 -07:00
Sam Lantinga 124a0050b6 Fixed warning: no previous prototype for function 'SDL_UpdateAudio' 2023-10-24 14:22:41 -07:00
Ryan C. Gordon b16165a33f
rwlock: SDL_UnlockRWLock was incorrectly tagged with SDL_RELEASE_SHARED.
It needs to be SDL_RELEASE_GENERIC, because it releases both exclusive
(writer) and shared (reader) locks.

Without this fix, clang's `-Wthread-safety` tests generate incorrect warnings.

Reference Issue #8096.
2023-10-24 14:42:02 -04:00
Ryan C. Gordon 865dd04068
pulseaudio: Don't use a hash for device change detection.
Both strings are _right there_ for comparing, so we can just set a flag to
note the device definitely changed.

Also simplified string management further; hotplug thread now makes a copy
of the string before releasing the lock if there was a change event, so when
the lock releases further events don't see a NULL and assume it's a new
device, causing a lot of work to ripple out and decide nothing has changed,
until the system stabilizes again. Now, it just does the right thing once.
2023-10-24 00:36:30 -04:00
Sam Lantinga b8cc51875a Fixed build 2023-10-23 19:36:14 -07:00
Sam Lantinga 0413e21e54 Fixed audio device removed events for ALSA
We don't match dev->name by string, since we might use the same string for both capture and output devices. Instead use the device pointer itself as the handle.

@icculus, are we guaranteed the device pointer is valid in ALSA_OpenDevice()?
2023-10-23 19:05:27 -07:00