Clarify which thread is the main thread
If video is initialized, the main thread is the one that initialized video, otherwise if events are initialized, the main thread is the thread that initialized events, otherwise the main thread is the one that called the main function. Fixes https://github.com/libsdl-org/SDL/issues/14511
This commit is contained in:
@@ -147,13 +147,19 @@ void SDL_QuitMainCallbacks(SDL_AppResult result)
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void SDL_CheckDefaultArgcArgv(int *argc, char ***argv)
|
||||
static void SDL_CheckDefaultArgcArgv(int *argc, char ***argv)
|
||||
{
|
||||
if (!argv)
|
||||
{
|
||||
if (!*argv) {
|
||||
static char dummyargv0[] = { 'S', 'D', 'L', '_', 'a', 'p', 'p', '\0' };
|
||||
static char *argvdummy[2] = { dummyargv0, NULL };
|
||||
*argc = 1;
|
||||
*argv = argvdummy;
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_CallMainFunction(int argc, char *argv[], SDL_main_func mainFunction)
|
||||
{
|
||||
SDL_CheckDefaultArgcArgv(&argc, &argv);
|
||||
SDL_SetMainReady();
|
||||
return mainFunction(argc, argv);
|
||||
}
|
||||
|
||||
@@ -27,10 +27,7 @@ SDL_AppResult SDL_InitMainCallbacks(int argc, char *argv[], SDL_AppInit_func app
|
||||
SDL_AppResult SDL_IterateMainCallbacks(bool pump_events);
|
||||
void SDL_QuitMainCallbacks(SDL_AppResult result);
|
||||
|
||||
// (not a callback thing, but convenient to stick this in here.)
|
||||
// If *_argv is NULL, update *_argc and *_argv to point at a static array of { "SDL_app", NULL }.
|
||||
void SDL_CheckDefaultArgcArgv(int *_argc, char ***_argv);
|
||||
// Check args and call the main function
|
||||
extern int SDL_CallMainFunction(int argc, char *argv[], SDL_main_func mainFunction);
|
||||
|
||||
#endif // SDL_main_callbacks_h_
|
||||
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@
|
||||
int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserved)
|
||||
{
|
||||
(void)reserved;
|
||||
SDL_CheckDefaultArgcArgv(&argc, &argv);
|
||||
return mainFunction(argc, argv);
|
||||
return SDL_CallMainFunction(argc, argv, mainFunction);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -37,8 +37,6 @@ int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserv
|
||||
{
|
||||
(void)reserved;
|
||||
|
||||
SDL_CheckDefaultArgcArgv(&argc, &argv);
|
||||
|
||||
// Move any URL params that start with "SDL_" over to environment
|
||||
// variables, so the hint system can pick them up, etc, much like a user
|
||||
// can set them from a shell prompt on a desktop machine. Ignore all
|
||||
@@ -59,7 +57,7 @@ int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserv
|
||||
}
|
||||
}, SDL_setenv_unsafe);
|
||||
|
||||
return mainFunction(argc, argv);
|
||||
return SDL_CallMainFunction(argc, argv, mainFunction);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,7 @@ extern "C" {
|
||||
#include "../../core/gdk/SDL_gdk.h"
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#include "../SDL_main_callbacks.h"
|
||||
}
|
||||
#include <XGameRuntime.h>
|
||||
#include <xsapi-c/services_c.h>
|
||||
@@ -65,14 +66,12 @@ int SDL_RunApp(int argc, char **argv, SDL_main_func mainFunction, void *reserved
|
||||
SDL_SetError("[GDK] Unable to get titleid. Will not call XblInitialize. Check MicrosoftGame.config!");
|
||||
}
|
||||
|
||||
SDL_SetMainReady();
|
||||
|
||||
if (!GDK_RegisterChangeNotifications()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Run the application main() code
|
||||
result = mainFunction(argc, argv);
|
||||
result = SDL_CallMainFunction(argc, argv, mainFunction);
|
||||
|
||||
GDK_UnregisterChangeNotifications();
|
||||
|
||||
|
||||
@@ -31,14 +31,11 @@ int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserv
|
||||
{
|
||||
int result;
|
||||
|
||||
SDL_CheckDefaultArgcArgv(&argc, &argv);
|
||||
|
||||
// init
|
||||
osSetSpeedupEnable(true);
|
||||
romfsInit();
|
||||
|
||||
SDL_SetMainReady();
|
||||
result = mainFunction(argc, argv);
|
||||
result = SDL_CallMainFunction(argc, argv, mainFunction);
|
||||
|
||||
// quit
|
||||
romfsExit();
|
||||
|
||||
@@ -68,21 +68,17 @@ static void deinit_drivers(void)
|
||||
|
||||
int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserved)
|
||||
{
|
||||
int res;
|
||||
int result;
|
||||
(void)reserved;
|
||||
|
||||
SDL_CheckDefaultArgcArgv(&argc, &argv);
|
||||
|
||||
prepare_IOP();
|
||||
init_drivers();
|
||||
|
||||
SDL_SetMainReady();
|
||||
|
||||
res = mainFunction(argc, argv);
|
||||
result = SDL_CallMainFunction(argc, argv, mainFunction);
|
||||
|
||||
deinit_drivers();
|
||||
|
||||
return res;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // SDL_PLATFORM_PS2
|
||||
|
||||
@@ -74,13 +74,9 @@ int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserv
|
||||
{
|
||||
(void)reserved;
|
||||
|
||||
SDL_CheckDefaultArgcArgv(&argc, &argv);
|
||||
|
||||
sdl_psp_setup_callbacks();
|
||||
|
||||
SDL_SetMainReady();
|
||||
|
||||
return mainFunction(argc, argv);
|
||||
return SDL_CallMainFunction(argc, argv, mainFunction);
|
||||
}
|
||||
|
||||
#endif // SDL_PLATFORM_PSP
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#ifdef SDL_PLATFORM_WIN32
|
||||
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
#include "../SDL_main_callbacks.h"
|
||||
|
||||
/* Win32-specific SDL_RunApp(), which does most of the SDL_main work,
|
||||
based on SDL_windows_main.c, placed in the public domain by Sam Lantinga 4/13/98 */
|
||||
@@ -37,8 +38,7 @@ int MINGW32_FORCEALIGN SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunc
|
||||
if (args_error) {
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal Error", args_error, NULL);
|
||||
} else {
|
||||
SDL_SetMainReady();
|
||||
result = mainFunction(argc, argv);
|
||||
result = SDL_CallMainFunction(argc, argv, mainFunction);
|
||||
if (heap_allocated) {
|
||||
HeapFree(GetProcessHeap(), 0, heap_allocated);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user