Added some extra protection to notify the developer if they haven't initialized the application properly.
This will help reduce issues like that reported in bug 1819: Wouter van Oortmerssen 2013-04-23 20:12:07 EDT #0 0x01d1e881 in __HALT () #1 0x01c58971 in _CFRuntimeCreateInstance () #2 0x02e4acc1 in GSFontCreateWithName () #3 0x00adc0e1 in UINewFont () #4 0x00adc24c in +[UIFont systemFontOfSize:traits:] () #5 0x00adc298 in +[UIFont systemFontOfSize:] () #6 0x009fb5d9 in +[UITextFieldLabel defaultFont] () #7 0x00a8ccd5 in -[UILabel _commonInit] () #8 0x00a8ce14 in -[UILabel initWithFrame:] () #9 0x00a052eb in -[UITextField createTextLabelWithTextColor:] () #10 0x009fbede in -[UITextField initWithFrame:] () #11 0x00152ead in -[SDL_uikitview initializeKeyboard] at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/uikit/SDL_uikitview.m:208 #12 0x0015290c in -[SDL_uikitview initWithFrame:] at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/uikit/SDL_uikitview.m:50 #13 0x00153b5b in -[SDL_uikitopenglview initWithFrame:scale:retainBacking:rBits:gBits:bBits:aBits:depthBits:stencilBits:majorVersion:] at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/uikit/SDL_uikitopenglview.m:53 #14 0x001524ff in UIKit_GL_CreateContext at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/uikit/SDL_uikitopengles.m:114 #15 0x0015078f in SDL_GL_CreateContext at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/SDL_video.c:2666 #16 0x000d8c5c in SDLInit(char const*, vec<int, 2>&) at /Users/aardappel/lobster/dev/xcode/lobster/../../src/sdlsystem.cpp:193
This commit is contained in:
parent
8731286cb4
commit
47f2eaf415
6 changed files with 33 additions and 3 deletions
|
@ -72,6 +72,15 @@ extern C_LINKAGE int SDL_main(int argc, char *argv[]);
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is called by the real SDL main function to let the rest of the
|
||||||
|
* library know that initialization was done properly.
|
||||||
|
*
|
||||||
|
* Calling this yourself without knowing what you're doing can cause
|
||||||
|
* crashes and hard to diagnose problems with your application.
|
||||||
|
*/
|
||||||
|
extern DECLSPEC void SDL_SetMainReady(void);
|
||||||
|
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
16
src/SDL.c
16
src/SDL.c
|
@ -43,6 +43,11 @@ extern int SDL_HelperWindowDestroy(void);
|
||||||
|
|
||||||
|
|
||||||
/* The initialized subsystems */
|
/* The initialized subsystems */
|
||||||
|
#ifdef SDL_MAIN_NEEDED
|
||||||
|
static SDL_bool SDL_MainIsReady = SDL_FALSE;
|
||||||
|
#else
|
||||||
|
static SDL_bool SDL_MainIsReady = SDL_TRUE;
|
||||||
|
#endif
|
||||||
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
|
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
|
||||||
static Uint8 SDL_SubsystemRefCount[ 32 ];
|
static Uint8 SDL_SubsystemRefCount[ 32 ];
|
||||||
|
|
||||||
|
@ -88,9 +93,20 @@ SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) {
|
||||||
return SDL_SubsystemRefCount[subsystem_index] == 1 || SDL_bInMainQuit;
|
return SDL_SubsystemRefCount[subsystem_index] == 1 || SDL_bInMainQuit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SDL_SetMainReady(void)
|
||||||
|
{
|
||||||
|
SDL_MainIsReady = SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
SDL_InitSubSystem(Uint32 flags)
|
SDL_InitSubSystem(Uint32 flags)
|
||||||
{
|
{
|
||||||
|
if (!SDL_MainIsReady) {
|
||||||
|
SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
#if !SDL_TIMERS_DISABLED
|
#if !SDL_TIMERS_DISABLED
|
||||||
SDL_InitTicks();
|
SDL_InitTicks();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,6 +20,8 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass c
|
||||||
/* This interface could expand with ABI negotiation, calbacks, etc. */
|
/* This interface could expand with ABI negotiation, calbacks, etc. */
|
||||||
SDL_Android_Init(env, cls);
|
SDL_Android_Init(env, cls);
|
||||||
|
|
||||||
|
SDL_SetMainReady();
|
||||||
|
|
||||||
/* Run the application code! */
|
/* Run the application code! */
|
||||||
int status;
|
int status;
|
||||||
char *argv[2];
|
char *argv[2];
|
||||||
|
|
|
@ -37,8 +37,6 @@
|
||||||
PSP_MAIN_THREAD_STACK_SIZE, etc.
|
PSP_MAIN_THREAD_STACK_SIZE, etc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int SDL_main(int argc, char *argv[]);
|
|
||||||
|
|
||||||
PSP_MODULE_INFO("SDL App", 0, 1, 1);
|
PSP_MODULE_INFO("SDL App", 0, 1, 1);
|
||||||
|
|
||||||
int sdl_psp_exit_callback(int arg1, int arg2, void *common)
|
int sdl_psp_exit_callback(int arg1, int arg2, void *common)
|
||||||
|
@ -75,6 +73,8 @@ int main(int argc, char *argv[])
|
||||||
/* Register sceKernelExitGame() to be called when we exit */
|
/* Register sceKernelExitGame() to be called when we exit */
|
||||||
atexit(sceKernelExitGame);
|
atexit(sceKernelExitGame);
|
||||||
|
|
||||||
|
SDL_SetMainReady();
|
||||||
|
|
||||||
(void)SDL_main(argc, argv);
|
(void)SDL_main(argc, argv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,8 @@ console_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
SDL_SetMainReady();
|
||||||
|
|
||||||
/* Run the application main() code */
|
/* Run the application main() code */
|
||||||
status = SDL_main(argc, argv);
|
status = SDL_main(argc, argv);
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
#undef main
|
#undef main
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int SDL_main(int argc, char *argv[]);
|
|
||||||
static int forward_argc;
|
static int forward_argc;
|
||||||
static char **forward_argv;
|
static char **forward_argv;
|
||||||
static int exit_status;
|
static int exit_status;
|
||||||
|
@ -187,6 +186,8 @@ static void SDL_IdleTimerDisabledChanged(const char *name, const char *oldValue,
|
||||||
|
|
||||||
- (void)postFinishLaunch
|
- (void)postFinishLaunch
|
||||||
{
|
{
|
||||||
|
SDL_SetMainReady();
|
||||||
|
|
||||||
/* run the user's application, passing argc and argv */
|
/* run the user's application, passing argc and argv */
|
||||||
SDL_iPhoneSetEventPump(SDL_TRUE);
|
SDL_iPhoneSetEventPump(SDL_TRUE);
|
||||||
exit_status = SDL_main(forward_argc, forward_argv);
|
exit_status = SDL_main(forward_argc, forward_argv);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue