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 6308263e2c049c22
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
     1.1 --- a/include/SDL_rwops.h	Fri May 25 15:10:13 2012 -0300
     1.2 +++ b/include/SDL_rwops.h	Fri May 25 15:35:41 2012 -0300
     1.3 @@ -85,11 +85,8 @@
     1.4  #if defined(ANDROID)
     1.5          struct
     1.6          {
     1.7 -            void *fileName;
     1.8              void *fileNameRef;
     1.9 -            void *inputStream;
    1.10              void *inputStreamRef;
    1.11 -            void *readableByteChannel;
    1.12              void *readableByteChannelRef;
    1.13              void *readMethod;
    1.14              long position;
     2.1 --- a/src/core/android/SDL_android.cpp	Fri May 25 15:10:13 2012 -0300
     2.2 +++ b/src/core/android/SDL_android.cpp	Fri May 25 15:35:41 2012 -0300
     2.3 @@ -442,7 +442,7 @@
     2.4          goto failure;
     2.5      }
     2.6  
     2.7 -    fileNameJString = (jstring)ctx->hidden.androidio.fileName;
     2.8 +    fileNameJString = (jstring)ctx->hidden.androidio.fileNameRef;
     2.9  
    2.10      // context = SDLActivity.getContext();
    2.11      mid = mEnv->GetStaticMethodID(mActivityClass,
    2.12 @@ -462,7 +462,6 @@
    2.13          goto failure;
    2.14      }
    2.15  
    2.16 -    ctx->hidden.androidio.inputStream = inputStream;
    2.17      ctx->hidden.androidio.inputStreamRef = mEnv->NewGlobalRef(inputStream);
    2.18  
    2.19      // Despite all the visible documentation on [Asset]InputStream claiming
    2.20 @@ -490,7 +489,6 @@
    2.21          goto failure;
    2.22      }
    2.23  
    2.24 -    ctx->hidden.androidio.readableByteChannel = readableByteChannel;
    2.25      ctx->hidden.androidio.readableByteChannelRef =
    2.26          mEnv->NewGlobalRef(readableByteChannel);
    2.27  
    2.28 @@ -510,6 +508,11 @@
    2.29          if(ctx->hidden.androidio.inputStreamRef != NULL) {
    2.30              mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.inputStreamRef);
    2.31          }
    2.32 +
    2.33 +        if(ctx->hidden.androidio.readableByteChannelRef != NULL) {
    2.34 +            mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.readableByteChannelRef);
    2.35 +        }
    2.36 +
    2.37      }
    2.38  
    2.39      return result;
    2.40 @@ -529,7 +532,6 @@
    2.41      }
    2.42  
    2.43      jstring fileNameJString = mEnv->NewStringUTF(fileName);
    2.44 -    ctx->hidden.androidio.fileName = fileNameJString;
    2.45      ctx->hidden.androidio.fileNameRef = mEnv->NewGlobalRef(fileNameJString);
    2.46      ctx->hidden.androidio.inputStreamRef = NULL;
    2.47  
    2.48 @@ -547,7 +549,7 @@
    2.49          return -1;
    2.50      }
    2.51  
    2.52 -    jobject readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannel;
    2.53 +    jobject readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannelRef;
    2.54      jmethodID readMethod = (jmethodID)ctx->hidden.androidio.readMethod;
    2.55      jobject byteBuffer = mEnv->NewDirectByteBuffer(buffer, bytesRemaining);
    2.56  
    2.57 @@ -593,7 +595,7 @@
    2.58              mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.fileNameRef);
    2.59          }
    2.60  
    2.61 -        jobject inputStream = (jobject)ctx->hidden.androidio.inputStream;
    2.62 +        jobject inputStream = (jobject)ctx->hidden.androidio.inputStreamRef;
    2.63  
    2.64          // inputStream.close();
    2.65          jmethodID mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream),
    2.66 @@ -640,7 +642,7 @@
    2.67      }
    2.68  
    2.69      long movement = newPosition - ctx->hidden.androidio.position;
    2.70 -    jobject inputStream = (jobject)ctx->hidden.androidio.inputStream;
    2.71 +    jobject inputStream = (jobject)ctx->hidden.androidio.inputStreamRef;
    2.72  
    2.73      if (movement > 0) {
    2.74          unsigned char buffer[1024];