Commit Graph

13835 Commits (43571769f16b45ddcb9d7dd1d4c6e21cd39e691e)

Author SHA1 Message Date
Sam Lantinga b9784feb24 Fixed potential uninitialized memory access (thanks Mathieu!)
GetRawInputDeviceList() can return a different number of devices than was allocated.

Fixes https://github.com/libsdl-org/SDL/issues/2759
2023-11-04 21:11:53 -07:00
Sam Lantinga 75ea3a8d32 Dynamically allocate long text for SDL_EVENT_TEXT_INPUT events
This prevents input text from being split across Unicode combining or modifier characters, and in practice allocations will rarely happen.
2023-11-04 20:55:10 -07:00
Sam Lantinga 2a1660ab51 Additional cleanup for SDL_RWprintf() (thanks @sezero!) 2023-11-04 20:47:08 -07:00
Ryan C. Gordon e5f2cea234
Sync wiki -> headers 2023-11-04 22:18:38 -04:00
Sam Lantinga ad842dd5ad Fixed a typo in SDL_log.h 2023-11-04 16:46:08 -07:00
Sam Lantinga f9d11807c0 Added SDL_RWprintf() and SDL_RWvprintf() to do formatted printing to an SDL_rwops stream
Fixes https://github.com/libsdl-org/SDL/issues/2390
2023-11-04 16:46:08 -07:00
Frank Praznik 52c4e3eab3 events: Update self-referential pointers when copying event objects
Pointers to static internal data need to be updated when copying events, or the cleanup code will attempt to free old stack data that went out of scope.
2023-11-04 18:07:24 -04:00
Sam Lantinga 91f0456391 Add the source application for drag and drop events (thanks Nathan!)
This is only implemented on iOS, but is useful for third party application integrations.

Fixes https://github.com/libsdl-org/SDL/issues/2024
2023-11-04 13:00:41 -07:00
Ryan C. Gordon 1a8bf31a69 include: Fixing whitespace on SDL_MixAudioFormat. 2023-11-04 15:06:41 -04:00
Sam Lantinga d07a264a9b Use the default UCS2/UCS4 conversion rather than non-portable INTERNAL encoding
Fxies https://github.com/libsdl-org/SDL/issues/1497
2023-11-04 12:01:30 -07:00
Ryan C. Gordon 780b6612a9 wayland: Wayland_Vulkan_GetInstanceExtensions didn't set the count variable.
Fixes #8468.
2023-11-04 14:53:24 -04:00
Sam Lantinga 46b940d571 Updated documentation to note that the event callback is called on the same thread as the main iteration callback 2023-11-04 11:31:54 -07:00
Sam Lantinga 4481754359 Make sure we only dispatch events on the main thread when using application callbacks 2023-11-04 11:27:58 -07:00
Sam Lantinga 274da8561c Updated the migration guide to note that you can check the return value of SDL_AddEventWatch() 2023-11-04 10:42:28 -07:00
Sam Lantinga ad9dcdbbce Clarify that you should use the other field when reading the event 2023-11-04 09:58:35 -07:00
Ryan C. Gordon a19029e3c1
docs: Updated README-main-functions.md based on feedback. 2023-11-04 10:03:10 -04:00
Ryan C. Gordon 019468dc59
main: Check for SDL_AddEventWatch failure, now that it can report it. 2023-11-04 10:03:10 -04:00
Sam Lantinga 7e445da569 Added SDL_CleanupEvent()
This is used to free any dynamically allocated memory in events.
2023-11-04 06:47:24 -07:00
Ivan Mogilko c4bf05fd9d Added subsystem refcount tests to testautomation 2023-11-04 00:52:08 -07:00
Ivan Mogilko 7f65ed6461 Handle subsystem dependencies recursively
Existing code is erroneous, because it adds or removes dependency's ref count based on number of InitSubSystem/QuitSubSystem calls, while ref count diff should depend on number of inited or quit dependents.
Recursive approach seems to be simplest solution that guarantees proper ref count.
2023-11-04 00:52:08 -07:00
Sam Lantinga a6b85c81cc Fixed build 2023-11-03 22:38:01 -07:00
SDL Wiki Bot 3ab6670cb1 Sync SDL3 wiki -> header 2023-11-04 05:36:15 +00:00
Sam Lantinga f439ccfc1a Updated return values for SDL event functions
SDL_PollEvent(), SDL_WaitEvent(), and SDL_WaitEventTimeout() all return SDL_bool.
SDL_AddEventWatch() returns an int result code.

Also improved timeout accuracy in SDL_WaitEventTimeout()
2023-11-03 22:31:42 -07:00
Sam Lantinga e0379c3b37 Grab events in large chunks in SDL_IterateMainCallbacks()
This is more efficient, especially since we're just going to discard them.
2023-11-03 21:47:44 -07:00
Sam Lantinga ad5264e54f Don't run SDL_IterateMainCallbacks() if the init call returns an exit code
This fixes a crash in testsprite if you pass invalid command line parameters.
2023-11-03 21:35:42 -07:00
Sam Lantinga dad1a84be4 Fixed building Vivante video driver 2023-11-03 14:56:15 -07:00
Sam Lantinga fe175d025f Fixed building Vivante video driver 2023-11-03 14:54:11 -07:00
Sam Lantinga 0b460f34ba The HP HyperX controllers have a share button 2023-11-03 14:47:20 -07:00
Sam Lantinga f3261fedcc Code cleanup now that SDL_bool is equivalent to a C boolean expression 2023-11-03 09:54:04 -07:00
Sam Lantinga a76d8e39aa Changed SDL_bool from an enum to unsigned int
Fixes https://github.com/libsdl-org/SDL/issues/7957
2023-11-03 09:54:04 -07:00
SDL Wiki Bot cf7e5bd0e8 Sync SDL3 wiki -> header 2023-11-03 15:41:14 +00:00
Ryan C. Gordon 853c28e624
docs: Added first draft of README-main-functions.md
Reference PR #8247.
2023-11-03 11:39:53 -04:00
Ryan C. Gordon 70d75b4a23
Sync wiki -> headers 2023-11-03 10:13:46 -04:00
Sam Lantinga ea02630143 More audio migration clarification 2023-11-03 00:28:05 -07:00
Sam Lantinga 14980b25a8 Clarify documentation for audio callback migration 2023-11-02 22:32:25 -07:00
Anonymous Maarten 6cf84e2c5b cmake: fold HAVE_INPUT_EVENTS into HAVE_LINUX_INPUT_H 2023-11-02 21:31:37 +01:00
Ozkan Sezer 5e869d1b35 fix Cocoa_Vulkan_GetInstanceExtensions prototype for Mac 2023-11-02 22:12:56 +03:00
Ryan C. Gordon 07a776f255
include: Fixed documentation for SDL_Vulkan_GetInstanceExtensions. 2023-11-02 15:12:24 -04:00
Ryan C. Gordon 5b3a2c6df6
docs: Updated SDL_Vulkan_GetInstanceExtensions info in README-migration.md.
Reference PR #8457.
2023-11-02 14:57:13 -04:00
ilyas-taouaou 9224a0a2d8 Fix emscripten, android, uikit and windows 2023-11-02 14:27:36 -04:00
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