Commit aa76adf4 authored by Tim Angus's avatar Tim Angus

* Android's InputStream::skip is apparently buggy, so instead read into a dummy buffer

parent 116a6faf
...@@ -89,7 +89,6 @@ typedef struct SDL_RWops ...@@ -89,7 +89,6 @@ typedef struct SDL_RWops
void *fileNameRef; void *fileNameRef;
void *inputStream; void *inputStream;
void *inputStreamRef; void *inputStreamRef;
void *skipMethod;
void *readableByteChannel; void *readableByteChannel;
void *readableByteChannelRef; void *readableByteChannelRef;
void *readMethod; void *readMethod;
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "SDL_android.h" #include "SDL_android.h"
#include <algorithm>
extern "C" { extern "C" {
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
#include "../../video/android/SDL_androidkeyboard.h" #include "../../video/android/SDL_androidkeyboard.h"
...@@ -346,11 +348,6 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx) ...@@ -346,11 +348,6 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx)
ctx->hidden.androidio.inputStream = inputStream; ctx->hidden.androidio.inputStream = inputStream;
ctx->hidden.androidio.inputStreamRef = mEnv->NewGlobalRef(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 // Despite all the visible documentation on [Asset]InputStream claiming
// that the .available() method is not guaranteed to return the entire file // that the .available() method is not guaranteed to return the entire file
// size, comments in <sdk>/samples/<ver>/ApiDemos/src/com/example/ ... // size, comments in <sdk>/samples/<ver>/ApiDemos/src/com/example/ ...
...@@ -518,16 +515,21 @@ extern "C" long Android_JNI_FileSeek(SDL_RWops* ctx, long offset, int whence) ...@@ -518,16 +515,21 @@ extern "C" long Android_JNI_FileSeek(SDL_RWops* ctx, long offset, int whence)
long movement = newPosition - ctx->hidden.androidio.position; long movement = newPosition - ctx->hidden.androidio.position;
jobject inputStream = (jobject)ctx->hidden.androidio.inputStream; jobject inputStream = (jobject)ctx->hidden.androidio.inputStream;
jmethodID skipMethod = (jmethodID)ctx->hidden.androidio.skipMethod;
if (movement > 0) { if (movement > 0) {
unsigned char buffer[1024];
// The easy case where we're seeking forwards // The easy case where we're seeking forwards
while (movement > 0) { while (movement > 0) {
// inputStream.skip(...); size_t result = Android_JNI_FileRead(ctx, buffer, 1,
movement -= mEnv->CallLongMethod(inputStream, skipMethod, movement); std::min(movement, (long)sizeof(buffer)));
if (Android_JNI_ExceptionOccurred()) {
if (result <= 0) {
// Failed to read/skip the required amount, so fail
return -1; return -1;
} }
movement -= result;
} }
} else if (movement < 0) { } else if (movement < 0) {
// We can't seek backwards so we have to reopen the file and seek // We can't seek backwards so we have to reopen the file and seek
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment