# HG changeset patch # User Tim Angus # Date 1318609789 -3600 # Node ID c9cb52d6d8646129e7ce69ad8074222c37d0d98f # Parent f4b73deb9d2666a1ff246bf92fbdb0faa94fe20f * Android's InputStream::skip is apparently buggy, so instead read into a dummy buffer diff -r f4b73deb9d26 -r c9cb52d6d864 include/SDL_rwops.h --- a/include/SDL_rwops.h Thu Oct 13 01:30:01 2011 -0400 +++ b/include/SDL_rwops.h Fri Oct 14 17:29:49 2011 +0100 @@ -89,7 +89,6 @@ void *fileNameRef; void *inputStream; void *inputStreamRef; - void *skipMethod; void *readableByteChannel; void *readableByteChannelRef; void *readMethod; diff -r f4b73deb9d26 -r c9cb52d6d864 src/core/android/SDL_android.cpp --- a/src/core/android/SDL_android.cpp Thu Oct 13 01:30:01 2011 -0400 +++ b/src/core/android/SDL_android.cpp Fri Oct 14 17:29:49 2011 +0100 @@ -23,6 +23,8 @@ #include "SDL_android.h" +#include + extern "C" { #include "../../events/SDL_events_c.h" #include "../../video/android/SDL_androidkeyboard.h" @@ -346,11 +348,6 @@ ctx->hidden.androidio.inputStream = inputStream; ctx->hidden.androidio.inputStreamRef = mEnv->NewGlobalRef(inputStream); - // Store .skip id for seeking purposes - mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream), - "skip", "(J)J"); - ctx->hidden.androidio.skipMethod = mid; - // Despite all the visible documentation on [Asset]InputStream claiming // that the .available() method is not guaranteed to return the entire file // size, comments in /samples//ApiDemos/src/com/example/ ... @@ -518,16 +515,21 @@ long movement = newPosition - ctx->hidden.androidio.position; jobject inputStream = (jobject)ctx->hidden.androidio.inputStream; - jmethodID skipMethod = (jmethodID)ctx->hidden.androidio.skipMethod; if (movement > 0) { + unsigned char buffer[1024]; + // The easy case where we're seeking forwards while (movement > 0) { - // inputStream.skip(...); - movement -= mEnv->CallLongMethod(inputStream, skipMethod, movement); - if (Android_JNI_ExceptionOccurred()) { + size_t result = Android_JNI_FileRead(ctx, buffer, 1, + std::min(movement, (long)sizeof(buffer))); + + if (result <= 0) { + // Failed to read/skip the required amount, so fail return -1; } + + movement -= result; } } else if (movement < 0) { // We can't seek backwards so we have to reopen the file and seek