Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixes issue #1500 "SDL_RWops fails under Android 4" by removing stale…
Browse files Browse the repository at this point in the history
… Local Refs

and replacing them for their global equivalents.
  • Loading branch information
gabomdq committed May 25, 2012
1 parent 0f1520a commit 19f2068
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
3 changes: 0 additions & 3 deletions include/SDL_rwops.h
Expand Up @@ -85,11 +85,8 @@ typedef struct SDL_RWops
#if defined(ANDROID)
struct
{
void *fileName;
void *fileNameRef;
void *inputStream;
void *inputStreamRef;
void *readableByteChannel;
void *readableByteChannelRef;
void *readMethod;
long position;
Expand Down
16 changes: 9 additions & 7 deletions src/core/android/SDL_android.cpp
Expand Up @@ -442,7 +442,7 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx)
goto failure;
}

fileNameJString = (jstring)ctx->hidden.androidio.fileName;
fileNameJString = (jstring)ctx->hidden.androidio.fileNameRef;

// context = SDLActivity.getContext();
mid = mEnv->GetStaticMethodID(mActivityClass,
Expand All @@ -462,7 +462,6 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx)
goto failure;
}

ctx->hidden.androidio.inputStream = inputStream;
ctx->hidden.androidio.inputStreamRef = mEnv->NewGlobalRef(inputStream);

// Despite all the visible documentation on [Asset]InputStream claiming
Expand Down Expand Up @@ -490,7 +489,6 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx)
goto failure;
}

ctx->hidden.androidio.readableByteChannel = readableByteChannel;
ctx->hidden.androidio.readableByteChannelRef =
mEnv->NewGlobalRef(readableByteChannel);

Expand All @@ -510,6 +508,11 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx)
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;
Expand All @@ -529,7 +532,6 @@ extern "C" int Android_JNI_FileOpen(SDL_RWops* ctx,
}

jstring fileNameJString = mEnv->NewStringUTF(fileName);
ctx->hidden.androidio.fileName = fileNameJString;
ctx->hidden.androidio.fileNameRef = mEnv->NewGlobalRef(fileNameJString);
ctx->hidden.androidio.inputStreamRef = NULL;

Expand All @@ -547,7 +549,7 @@ extern "C" size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
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);

Expand Down Expand Up @@ -593,7 +595,7 @@ static int Android_JNI_FileClose(SDL_RWops* ctx, bool release)
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),
Expand Down Expand Up @@ -640,7 +642,7 @@ extern "C" long Android_JNI_FileSeek(SDL_RWops* ctx, long offset, int whence)
}

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];
Expand Down

0 comments on commit 19f2068

Please sign in to comment.