Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
aa76adf4
Commit
aa76adf4
authored
Oct 14, 2011
by
Tim Angus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* Android's InputStream::skip is apparently buggy, so instead read into a dummy buffer
parent
116a6faf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
10 deletions
+11
-10
SDL_rwops.h
include/SDL_rwops.h
+0
-1
SDL_android.cpp
src/core/android/SDL_android.cpp
+11
-9
No files found.
include/SDL_rwops.h
View file @
aa76adf4
...
...
@@ -89,7 +89,6 @@ typedef struct SDL_RWops
void
*
fileNameRef
;
void
*
inputStream
;
void
*
inputStreamRef
;
void
*
skipMethod
;
void
*
readableByteChannel
;
void
*
readableByteChannelRef
;
void
*
readMethod
;
...
...
src/core/android/SDL_android.cpp
View file @
aa76adf4
...
...
@@ -23,6 +23,8 @@
#include "SDL_android.h"
#include <algorithm>
extern
"C"
{
#include "../../events/SDL_events_c.h"
#include "../../video/android/SDL_androidkeyboard.h"
...
...
@@ -346,11 +348,6 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx)
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 <sdk>/samples/<ver>/ApiDemos/src/com/example/ ...
...
...
@@ -518,16 +515,21 @@ 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
;
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment