Fixes issue #1500 "SDL_RWops fails under Android 4" by removing stale Local Refs
authorGabriel Jacobo <gabomdq@gmail.com>
Fri, 25 May 2012 15:35:41 -0300
changeset 6308 263e2c049c22
parent 6307 6048116f40b1
child 6309 53a0e9f5db8d
Fixes issue #1500 "SDL_RWops fails under Android 4" by removing stale Local Refs and replacing them for their global equivalents.
include/SDL_rwops.h
src/core/android/SDL_android.cpp
--- a/include/SDL_rwops.h	Fri May 25 15:10:13 2012 -0300
+++ b/include/SDL_rwops.h	Fri May 25 15:35:41 2012 -0300
@@ -85,11 +85,8 @@
 #if defined(ANDROID)
         struct
         {
-            void *fileName;
             void *fileNameRef;
-            void *inputStream;
             void *inputStreamRef;
-            void *readableByteChannel;
             void *readableByteChannelRef;
             void *readMethod;
             long position;
--- a/src/core/android/SDL_android.cpp	Fri May 25 15:10:13 2012 -0300
+++ b/src/core/android/SDL_android.cpp	Fri May 25 15:35:41 2012 -0300
@@ -442,7 +442,7 @@
         goto failure;
     }
 
-    fileNameJString = (jstring)ctx->hidden.androidio.fileName;
+    fileNameJString = (jstring)ctx->hidden.androidio.fileNameRef;
 
     // context = SDLActivity.getContext();
     mid = mEnv->GetStaticMethodID(mActivityClass,
@@ -462,7 +462,6 @@
         goto failure;
     }
 
-    ctx->hidden.androidio.inputStream = inputStream;
     ctx->hidden.androidio.inputStreamRef = mEnv->NewGlobalRef(inputStream);
 
     // Despite all the visible documentation on [Asset]InputStream claiming
@@ -490,7 +489,6 @@
         goto failure;
     }
 
-    ctx->hidden.androidio.readableByteChannel = readableByteChannel;
     ctx->hidden.androidio.readableByteChannelRef =
         mEnv->NewGlobalRef(readableByteChannel);
 
@@ -510,6 +508,11 @@
         if(ctx->hidden.androidio.inputStreamRef != NULL) {
             mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.inputStreamRef);
         }
+
+        if(ctx->hidden.androidio.readableByteChannelRef != NULL) {
+            mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.readableByteChannelRef);
+        }
+
     }
 
     return result;
@@ -529,7 +532,6 @@
     }
 
     jstring fileNameJString = mEnv->NewStringUTF(fileName);
-    ctx->hidden.androidio.fileName = fileNameJString;
     ctx->hidden.androidio.fileNameRef = mEnv->NewGlobalRef(fileNameJString);
     ctx->hidden.androidio.inputStreamRef = NULL;
 
@@ -547,7 +549,7 @@
         return -1;
     }
 
-    jobject readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannel;
+    jobject readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannelRef;
     jmethodID readMethod = (jmethodID)ctx->hidden.androidio.readMethod;
     jobject byteBuffer = mEnv->NewDirectByteBuffer(buffer, bytesRemaining);
 
@@ -593,7 +595,7 @@
             mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.fileNameRef);
         }
 
-        jobject inputStream = (jobject)ctx->hidden.androidio.inputStream;
+        jobject inputStream = (jobject)ctx->hidden.androidio.inputStreamRef;
 
         // inputStream.close();
         jmethodID mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream),
@@ -640,7 +642,7 @@
     }
 
     long movement = newPosition - ctx->hidden.androidio.position;
-    jobject inputStream = (jobject)ctx->hidden.androidio.inputStream;
+    jobject inputStream = (jobject)ctx->hidden.androidio.inputStreamRef;
 
     if (movement > 0) {
         unsigned char buffer[1024];