Skip to content

Latest commit

 

History

History
85 lines (66 loc) · 2.39 KB

SDL_android_main.c

File metadata and controls

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