Android: C89 cleanup to avoid warnings/errors since the default gcc mode on Android is still pre-C99.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 44f6e80..4984349 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -561,6 +561,7 @@ int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, i
{
jboolean audioBufferStereo;
int audioBufferFrames;
+ jboolean isCopy;
JNIEnv *env = Android_JNI_GetEnv();
@@ -602,7 +603,7 @@ int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, i
return 0;
}
- jboolean isCopy = JNI_FALSE;
+ isCopy = JNI_FALSE;
if (audioBuffer16Bit) {
audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy);
audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer);
@@ -654,10 +655,12 @@ void Android_JNI_CloseAudioDevice(void)
/* If the parameter silent is truthy then SDL_SetError() will not be called. */
static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
{
- SDL_assert(LocalReferenceHolder_IsActive());
JNIEnv *mEnv = Android_JNI_GetEnv();
+ jthrowable exception;
+
+ SDL_assert(LocalReferenceHolder_IsActive());
- jthrowable exception = (*mEnv)->ExceptionOccurred(mEnv);
+ exception = (*mEnv)->ExceptionOccurred(mEnv);
if (exception != NULL) {
jmethodID mid;
@@ -667,13 +670,16 @@ static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
if (!silent) {
jclass exceptionClass = (*mEnv)->GetObjectClass(mEnv, exception);
jclass classClass = (*mEnv)->FindClass(mEnv, "java/lang/Class");
+ jstring exceptionName;
+ const char* exceptionNameUTF8;
+ jstring exceptionMessage;
mid = (*mEnv)->GetMethodID(mEnv, classClass, "getName", "()Ljava/lang/String;");
- jstring exceptionName = (jstring)(*mEnv)->CallObjectMethod(mEnv, exceptionClass, mid);
- const char* exceptionNameUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionName, 0);
+ exceptionName = (jstring)(*mEnv)->CallObjectMethod(mEnv, exceptionClass, mid);
+ exceptionNameUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionName, 0);
mid = (*mEnv)->GetMethodID(mEnv, exceptionClass, "getMessage", "()Ljava/lang/String;");
- jstring exceptionMessage = (jstring)(*mEnv)->CallObjectMethod(mEnv, exception, mid);
+ exceptionMessage = (jstring)(*mEnv)->CallObjectMethod(mEnv, exception, mid);
if (exceptionMessage != NULL) {
const char* exceptionMessageUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionMessage, 0);
@@ -856,6 +862,7 @@ int Android_JNI_FileOpen(SDL_RWops* ctx,
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
JNIEnv *mEnv = Android_JNI_GetEnv();
int retval;
+ jstring fileNameJString;
if (!LocalReferenceHolder_Init(&refs, mEnv)) {
LocalReferenceHolder_Cleanup(&refs);
@@ -867,7 +874,7 @@ int Android_JNI_FileOpen(SDL_RWops* ctx,
return -1;
}
- jstring fileNameJString = (*mEnv)->NewStringUTF(mEnv, fileName);
+ fileNameJString = (*mEnv)->NewStringUTF(mEnv, fileName);
ctx->hidden.androidio.fileNameRef = (*mEnv)->NewGlobalRef(mEnv, fileNameJString);
ctx->hidden.androidio.inputStreamRef = NULL;
ctx->hidden.androidio.readableByteChannelRef = NULL;
@@ -886,10 +893,11 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
if (ctx->hidden.androidio.assetFileDescriptorRef) {
size_t bytesMax = size * maxnum;
+ size_t result;
if (ctx->hidden.androidio.size != -1 /* UNKNOWN_LENGTH */ && ctx->hidden.androidio.position + bytesMax > ctx->hidden.androidio.size) {
bytesMax = ctx->hidden.androidio.size - ctx->hidden.androidio.position;
}
- size_t result = read(ctx->hidden.androidio.fd, buffer, bytesMax );
+ result = read(ctx->hidden.androidio.fd, buffer, bytesMax );
if (result > 0) {
ctx->hidden.androidio.position += result;
LocalReferenceHolder_Cleanup(&refs);
@@ -901,19 +909,23 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
jlong bytesRemaining = (jlong) (size * maxnum);
jlong bytesMax = (jlong) (ctx->hidden.androidio.size - ctx->hidden.androidio.position);
int bytesRead = 0;
+ JNIEnv *mEnv;
+ jobject readableByteChannel;
+ jmethodID readMethod;
+ jobject byteBuffer;
/* Don't read more bytes than those that remain in the file, otherwise we get an exception */
if (bytesRemaining > bytesMax) bytesRemaining = bytesMax;
- JNIEnv *mEnv = Android_JNI_GetEnv();
+ mEnv = Android_JNI_GetEnv();
if (!LocalReferenceHolder_Init(&refs, mEnv)) {
LocalReferenceHolder_Cleanup(&refs);
return 0;
}
- jobject readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannelRef;
- jmethodID readMethod = (jmethodID)ctx->hidden.androidio.readMethod;
- jobject byteBuffer = (*mEnv)->NewDirectByteBuffer(mEnv, buffer, bytesRemaining);
+ readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannelRef;
+ readMethod = (jmethodID)ctx->hidden.androidio.readMethod;
+ byteBuffer = (*mEnv)->NewDirectByteBuffer(mEnv, buffer, bytesRemaining);
while (bytesRemaining > 0) {
/* result = readableByteChannel.read(...); */
@@ -1003,6 +1015,7 @@ Sint64 Android_JNI_FileSize(SDL_RWops* ctx)
Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
{
if (ctx->hidden.androidio.assetFileDescriptorRef) {
+ off_t ret;
switch (whence) {
case RW_SEEK_SET:
if (ctx->hidden.androidio.size != -1 /* UNKNOWN_LENGTH */ && offset > ctx->hidden.androidio.size) offset = ctx->hidden.androidio.size;
@@ -1021,11 +1034,12 @@ Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
}
whence = SEEK_SET;
- off_t ret = lseek(ctx->hidden.androidio.fd, (off_t)offset, SEEK_SET);
+ ret = lseek(ctx->hidden.androidio.fd, (off_t)offset, SEEK_SET);
if (ret == -1) return -1;
ctx->hidden.androidio.position = ret - ctx->hidden.androidio.offset;
} else {
Sint64 newPosition;
+ Sint64 movement;
switch (whence) {
case RW_SEEK_SET:
@@ -1049,17 +1063,18 @@ Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
newPosition = ctx->hidden.androidio.size;
}
- Sint64 movement = newPosition - ctx->hidden.androidio.position;
+ movement = newPosition - ctx->hidden.androidio.position;
if (movement > 0) {
unsigned char buffer[4096];
/* The easy case where we're seeking forwards */
while (movement > 0) {
Sint64 amount = sizeof (buffer);
+ size_t result;
if (amount > movement) {
amount = movement;
}
- size_t result = Android_JNI_FileRead(ctx, buffer, 1, amount);
+ result = Android_JNI_FileRead(ctx, buffer, 1, amount);
if (result <= 0) {
/* Failed to read/skip the required amount, so fail */
return -1;
@@ -1092,21 +1107,23 @@ static jobject Android_JNI_GetSystemServiceObject(const char* name)
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
JNIEnv* env = Android_JNI_GetEnv();
jobject retval = NULL;
+ jstring service;
+ jmethodID mid;
+ jobject context;
+ jobject manager;
if (!LocalReferenceHolder_Init(&refs, env)) {
LocalReferenceHolder_Cleanup(&refs);
return NULL;
}
- jstring service = (*env)->NewStringUTF(env, name);
-
- jmethodID mid;
+ service = (*env)->NewStringUTF(env, name);
mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
- jobject context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
+ context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
mid = (*env)->GetMethodID(env, mActivityClass, "getSystemServiceFromUiThread", "(Ljava/lang/String;)Ljava/lang/Object;");
- jobject manager = (*env)->CallObjectMethod(env, context, mid, service);
+ manager = (*env)->CallObjectMethod(env, context, mid, service);
(*env)->DeleteLocalRef(env, service);
@@ -1118,11 +1135,12 @@ static jobject Android_JNI_GetSystemServiceObject(const char* name)
#define SETUP_CLIPBOARD(error) \
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); \
JNIEnv* env = Android_JNI_GetEnv(); \
+ jobject clipboard; \
if (!LocalReferenceHolder_Init(&refs, env)) { \
LocalReferenceHolder_Cleanup(&refs); \
return error; \
} \
- jobject clipboard = Android_JNI_GetSystemServiceObject("clipboard"); \
+ clipboard = Android_JNI_GetSystemServiceObject("clipboard"); \
if (!clipboard) { \
LocalReferenceHolder_Cleanup(&refs); \
return error; \
@@ -1133,14 +1151,17 @@ static jobject Android_JNI_GetSystemServiceObject(const char* name)
int Android_JNI_SetClipboardText(const char* text)
{
+ /* Watch out for C89 scoping rules because of the macro */
SETUP_CLIPBOARD(-1)
- jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, clipboard), "setText", "(Ljava/lang/CharSequence;)V");
- jstring string = (*env)->NewStringUTF(env, text);
- (*env)->CallVoidMethod(env, clipboard, mid, string);
- (*env)->DeleteGlobalRef(env, clipboard);
- (*env)->DeleteLocalRef(env, string);
-
+ /* Nest the following in a scope to avoid C89 declaration rules triggered by the macro */
+ {
+ jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, clipboard), "setText", "(Ljava/lang/CharSequence;)V");
+ jstring string = (*env)->NewStringUTF(env, text);
+ (*env)->CallVoidMethod(env, clipboard, mid, string);
+ (*env)->DeleteGlobalRef(env, clipboard);
+ (*env)->DeleteLocalRef(env, string);
+ }
CLEANUP_CLIPBOARD();
return 0;
@@ -1148,25 +1169,30 @@ int Android_JNI_SetClipboardText(const char* text)
char* Android_JNI_GetClipboardText(void)
{
+ /* Watch out for C89 scoping rules because of the macro */
SETUP_CLIPBOARD(SDL_strdup(""))
- jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, clipboard), "getText", "()Ljava/lang/CharSequence;");
- jobject sequence = (*env)->CallObjectMethod(env, clipboard, mid);
- (*env)->DeleteGlobalRef(env, clipboard);
- if (sequence) {
- mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, sequence), "toString", "()Ljava/lang/String;");
- jstring string = (jstring)((*env)->CallObjectMethod(env, sequence, mid));
- const char* utf = (*env)->GetStringUTFChars(env, string, 0);
- if (utf) {
- char* text = SDL_strdup(utf);
- (*env)->ReleaseStringUTFChars(env, string, utf);
-
- CLEANUP_CLIPBOARD();
-
- return text;
+ /* Nest the following in a scope to avoid C89 declaration rules triggered by the macro */
+ {
+ jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, clipboard), "getText", "()Ljava/lang/CharSequence;");
+ jobject sequence = (*env)->CallObjectMethod(env, clipboard, mid);
+ (*env)->DeleteGlobalRef(env, clipboard);
+ if (sequence) {
+ jstring string;
+ const char* utf;
+ mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, sequence), "toString", "()Ljava/lang/String;");
+ string = (jstring)((*env)->CallObjectMethod(env, sequence, mid));
+ utf = (*env)->GetStringUTFChars(env, string, 0);
+ if (utf) {
+ char* text = SDL_strdup(utf);
+ (*env)->ReleaseStringUTFChars(env, string, utf);
+
+ CLEANUP_CLIPBOARD();
+
+ return text;
+ }
}
}
-
CLEANUP_CLIPBOARD();
return SDL_strdup("");
@@ -1174,10 +1200,13 @@ char* Android_JNI_GetClipboardText(void)
SDL_bool Android_JNI_HasClipboardText(void)
{
+ jmethodID mid;
+ jboolean has;
+ /* Watch out for C89 scoping rules because of the macro */
SETUP_CLIPBOARD(SDL_FALSE)
- jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, clipboard), "hasText", "()Z");
- jboolean has = (*env)->CallBooleanMethod(env, clipboard, mid);
+ mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, clipboard), "hasText", "()Z");
+ has = (*env)->CallBooleanMethod(env, clipboard, mid);
(*env)->DeleteGlobalRef(env, clipboard);
CLEANUP_CLIPBOARD();
@@ -1194,49 +1223,61 @@ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seco
{
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
JNIEnv* env = Android_JNI_GetEnv();
+ jmethodID mid;
+ jobject context;
+ jstring action;
+ jclass cls;
+ jobject filter;
+ jobject intent;
+ jstring iname;
+ jmethodID imid;
+ jstring bname;
+ jmethodID bmid;
if (!LocalReferenceHolder_Init(&refs, env)) {
LocalReferenceHolder_Cleanup(&refs);
return -1;
}
- jmethodID mid;
mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
- jobject context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
+ context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
- jstring action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED");
+ action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED");
- jclass cls = (*env)->FindClass(env, "android/content/IntentFilter");
+ cls = (*env)->FindClass(env, "android/content/IntentFilter");
mid = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/lang/String;)V");
- jobject filter = (*env)->NewObject(env, cls, mid, action);
+ filter = (*env)->NewObject(env, cls, mid, action);
(*env)->DeleteLocalRef(env, action);
mid = (*env)->GetMethodID(env, mActivityClass, "registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;");
- jobject intent = (*env)->CallObjectMethod(env, context, mid, NULL, filter);
+ intent = (*env)->CallObjectMethod(env, context, mid, NULL, filter);
(*env)->DeleteLocalRef(env, filter);
cls = (*env)->GetObjectClass(env, intent);
- jstring iname;
- jmethodID imid = (*env)->GetMethodID(env, cls, "getIntExtra", "(Ljava/lang/String;I)I");
+ imid = (*env)->GetMethodID(env, cls, "getIntExtra", "(Ljava/lang/String;I)I");
+ /* Watch out for C89 scoping rules because of the macro */
#define GET_INT_EXTRA(var, key) \
+ int var; \
iname = (*env)->NewStringUTF(env, key); \
- int var = (*env)->CallIntMethod(env, intent, imid, iname, -1); \
+ var = (*env)->CallIntMethod(env, intent, imid, iname, -1); \
(*env)->DeleteLocalRef(env, iname);
- jstring bname;
- jmethodID bmid = (*env)->GetMethodID(env, cls, "getBooleanExtra", "(Ljava/lang/String;Z)Z");
+ bmid = (*env)->GetMethodID(env, cls, "getBooleanExtra", "(Ljava/lang/String;Z)Z");
+ /* Watch out for C89 scoping rules because of the macro */
#define GET_BOOL_EXTRA(var, key) \
+ int var; \
bname = (*env)->NewStringUTF(env, key); \
- int var = (*env)->CallBooleanMethod(env, intent, bmid, bname, JNI_FALSE); \
+ var = (*env)->CallBooleanMethod(env, intent, bmid, bname, JNI_FALSE); \
(*env)->DeleteLocalRef(env, bname);
if (plugged) {
+ /* Watch out for C89 scoping rules because of the macro */
GET_INT_EXTRA(plug, "plugged") /* == BatteryManager.EXTRA_PLUGGED (API 5) */
if (plug == -1) {
LocalReferenceHolder_Cleanup(&refs);
@@ -1248,6 +1289,7 @@ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seco
}
if (charged) {
+ /* Watch out for C89 scoping rules because of the macro */
GET_INT_EXTRA(status, "status") /* == BatteryManager.EXTRA_STATUS (API 5) */
if (status == -1) {
LocalReferenceHolder_Cleanup(&refs);
@@ -1267,8 +1309,20 @@ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seco
}
if (percent) {
- GET_INT_EXTRA(level, "level") /* == BatteryManager.EXTRA_LEVEL (API 5) */
- GET_INT_EXTRA(scale, "scale") /* == BatteryManager.EXTRA_SCALE (API 5) */
+ int level;
+ int scale;
+
+ /* Watch out for C89 scoping rules because of the macro */
+ {
+ GET_INT_EXTRA(level_temp, "level") /* == BatteryManager.EXTRA_LEVEL (API 5) */
+ level = level_temp;
+ }
+ /* Watch out for C89 scoping rules because of the macro */
+ {
+ GET_INT_EXTRA(scale_temp, "scale") /* == BatteryManager.EXTRA_SCALE (API 5) */
+ scale = scale_temp;
+ }
+
if ((level == -1) || (scale == -1)) {
LocalReferenceHolder_Cleanup(&refs);
return -1;
@@ -1321,14 +1375,16 @@ void Android_JNI_PollInputDevices(void)
int Android_JNI_SendMessage(int command, int param)
{
JNIEnv *env = Android_JNI_GetEnv();
+ jmethodID mid;
+ jboolean success;
if (!env) {
return -1;
}
- jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z");
+ mid = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z");
if (!mid) {
return -1;
}
- jboolean success = (*env)->CallStaticBooleanMethod(env, mActivityClass, mid, command, param);
+ success = (*env)->CallStaticBooleanMethod(env, mActivityClass, mid, command, param);
return success ? 0 : -1;
}
@@ -1340,11 +1396,12 @@ void Android_JNI_SuspendScreenSaver(SDL_bool suspend)
void Android_JNI_ShowTextInput(SDL_Rect *inputRect)
{
JNIEnv *env = Android_JNI_GetEnv();
+ jmethodID mid;
if (!env) {
return;
}
- jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "showTextInput", "(IIII)Z");
+ mid = (*env)->GetStaticMethodID(env, mActivityClass, "showTextInput", "(IIII)Z");
if (!mid) {
return;
}
diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c
index 8656a53..20c1779 100644
--- a/src/joystick/android/SDL_sysjoystick.c
+++ b/src/joystick/android/SDL_sysjoystick.c
@@ -323,6 +323,7 @@ Android_RemoveJoystick(int device_id)
{
SDL_joylist_item *item = SDL_joylist;
SDL_joylist_item *prev = NULL;
+ int retval;
#if !SDL_EVENTS_DISABLED
SDL_Event event;
#endif
@@ -340,7 +341,7 @@ Android_RemoveJoystick(int device_id)
return -1;
}
- const int retval = item->device_instance;
+ retval = item->device_instance;
if (item->joystick) {
item->joystick->hwdata = NULL;
}
diff --git a/src/main/android/SDL_android_main.c b/src/main/android/SDL_android_main.c
index 4173bcb..8a85ccf 100644
--- a/src/main/android/SDL_android_main.c
+++ b/src/main/android/SDL_android_main.c
@@ -22,6 +22,8 @@ JNIEXPORT int JNICALL Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jc
int i;
int argc;
int status;
+ int len;
+ char** argv;
/* This interface could expand with ABI negotiation, callbacks, etc. */
SDL_Android_Init(env, cls);
@@ -30,8 +32,8 @@ JNIEXPORT int JNICALL Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jc
/* Prepare the arguments. */
- int len = (*env)->GetArrayLength(env, array);
- char* argv[1 + len + 1];
+ len = (*env)->GetArrayLength(env, array);
+ argv = SDL_stack_alloc(char*, 1 + len + 1);
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
@@ -66,7 +68,7 @@ JNIEXPORT int JNICALL Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jc
for (i = 0; i < argc; ++i) {
SDL_free(argv[i]);
}
-
+ SDL_stack_free(argv);
/* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
/* exit(status); */