SDL_android_main.c (2087B)
1/* 2 SDL_android_main.c, placed in the public domain by Sam Lantinga 3/13/14 3*/ 4#include "../../SDL_internal.h" 5 6#ifdef __ANDROID__ 7 8/* Include the SDL main definition header */ 9#include "SDL_main.h" 10 11/******************************************************************************* 12 Functions called by JNI 13*******************************************************************************/ 14#include <jni.h> 15 16/* Called before SDL_main() to initialize JNI bindings in SDL library */ 17extern void SDL_Android_Init(JNIEnv* env, jclass cls); 18 19/* Start up the SDL app */ 20int Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject array) 21{ 22 int i; 23 int argc; 24 int status; 25 26 /* This interface could expand with ABI negotiation, callbacks, etc. */ 27 SDL_Android_Init(env, cls); 28 29 SDL_SetMainReady(); 30 31 /* Prepare the arguments. */ 32 33 int len = (*env)->GetArrayLength(env, array); 34 char* argv[1 + len + 1]; 35 argc = 0; 36 /* Use the name "app_process" so PHYSFS_platformCalcBaseDir() works. 37 https://bitbucket.org/MartinFelis/love-android-sdl2/issue/23/release-build-crash-on-start 38 */ 39 argv[argc++] = SDL_strdup("app_process"); 40 for (i = 0; i < len; ++i) { 41 const char* utf; 42 char* arg = NULL; 43 jstring string = (*env)->GetObjectArrayElement(env, array, i); 44 if (string) { 45 utf = (*env)->GetStringUTFChars(env, string, 0); 46 if (utf) { 47 arg = SDL_strdup(utf); 48 (*env)->ReleaseStringUTFChars(env, string, utf); 49 } 50 } 51 if (!arg) { 52 arg = SDL_strdup(""); 53 } 54 argv[argc++] = arg; 55 } 56 argv[argc] = NULL; 57 58 59 /* Run the application. */ 60 61 status = SDL_main(argc, argv); 62 63 /* Release the arguments. */ 64 65 for (i = 0; i < argc; ++i) { 66 SDL_free(argv[i]); 67 } 68 69 /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */ 70 /* exit(status); */ 71 72 return status; 73} 74 75#endif /* __ANDROID__ */ 76 77/* vi: set ts=4 sw=4 expandtab: */