Android

Hi,

This code

Code:
char fn = “recovery.rc”;
SDL_Log (“Try open file: %s”, fn);
for (int i=0; i<3000; ++i) {
SDL_RWops
rwo = SDL_RWFromFile (fn, “r”);
if (rwo) {
SDL_Log ("%d Ok", i);
SDL_RWclose (rwo);
} else {
SDL_Log (“ERROR: %s”, SDL_GetError());
}
}
return 0;

works like this:

Code:
W/SDL/APP (22744): Try open file: recovery.rc
W/SDL/APP (22744): 0 Ok
W/SDL/APP (22744): 1 Ok
W/SDL/APP (22744): 2 Ok
.
.
.

W/SDL/APP (22744): 1005 Ok
W/SDL/APP (22744): 1006 Ok
W/SDL/APP (22744): ERROR: Failed to allocate enough JVM local references
W/SDL/APP (22744): ERROR: Failed to allocate enough JVM local references
W/SDL/APP (22744): ERROR: Failed to allocate enough JVM local references
.
.
.

The number of successful attempts to vary, but always limited. Why?
I think this is a SDL error.

I think the native code needs to return to the “Java side” to actually release the references, that’s why you eventually run out. See here http://groups.google.com/group/android-ndk/browse_thread/thread/490e1ba73e3102b5------------------------
Gabriel Jacobo
mdqinc.com

Also, now that I think about it, I seem to recall that this issue was solved…are you using the latest SDL2 from HG?------------------------
Gabriel Jacobo
mdqinc.com

gabomdq wrote:

I think the native code needs to return to the “Java side” to actually release the references, that’s why you eventually run out. See here http://groups.google.com/group/android-ndk/browse_thread/thread/490e1ba73e3102b5

Thank you. I’ve already read it, but an error in the SDL can not fix yourself. While using a different way to work with the APK file, without the SDL.

gabomdq wrote:

are you using the latest SDL2 from HG?

The latest version of SDL behaves the same way.

The Android file code is in here:
src/core/android/SDL_android.cpp

From inspection, it looks to me like it’s doing the right thing. Does the
Java VM garbage collection need to kick in to actually close the file
references?On Thu, Feb 9, 2012 at 9:52 AM, Alexandr wrote:

**
Hi,

This code

Code:

char *fn = "recovery.rc";

SDL_Log (“Try open file: %s”, fn);
for (int i=0; i<3000; ++i) {
SDL_RWops* rwo = SDL_RWFromFile (fn, “r”);
if (rwo) {
SDL_Log ("%d Ok", i);
SDL_RWclose (rwo);
} else {
SDL_Log (“ERROR: %s”, SDL_GetError());
}
}
return 0;

works like this:

Code:

W/SDL/APP (22744): Try open file: recovery.rc
W/SDL/APP (22744): 0 Ok
W/SDL/APP (22744): 1 Ok
W/SDL/APP (22744): 2 Ok
.
.
.

W/SDL/APP (22744): 1005 Ok
W/SDL/APP (22744): 1006 Ok
W/SDL/APP (22744): ERROR: Failed to allocate enough JVM local references
W/SDL/APP (22744): ERROR: Failed to allocate enough JVM local references
W/SDL/APP (22744): ERROR: Failed to allocate enough JVM local references
.
.
.

The number of successful attempts to vary, but always limited. Why?
I think this is a SDL error.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

As long as the code is calling close() it should suffice.On Sat, Feb 11, 2012 at 7:36 AM, Sam Lantinga wrote:

The Android file code is in here:
src/core/android/SDL_android.cpp

From inspection, it looks to me like it’s doing the right thing. Does the
Java VM garbage collection need to kick in to actually close the file
references?

On Thu, Feb 9, 2012 at 9:52 AM, Alexandr wrote:

**
Hi,

This code

Code:

char *fn = "recovery.rc";

SDL_Log (“Try open file: %s”, fn);
for (int i=0; i<3000; ++i) {
SDL_RWops* rwo = SDL_RWFromFile (fn, “r”);
if (rwo) {
SDL_Log ("%d Ok", i);
SDL_RWclose (rwo);
} else {
SDL_Log (“ERROR: %s”, SDL_GetError());
}
}
return 0;

works like this:

Code:

W/SDL/APP (22744): Try open file: recovery.rc
W/SDL/APP (22744): 0 Ok
W/SDL/APP (22744): 1 Ok
W/SDL/APP (22744): 2 Ok
.
.
.

W/SDL/APP (22744): 1005 Ok
W/SDL/APP (22744): 1006 Ok
W/SDL/APP (22744): ERROR: Failed to allocate enough JVM local references
W/SDL/APP (22744): ERROR: Failed to allocate enough JVM local references
W/SDL/APP (22744): ERROR: Failed to allocate enough JVM local references
.
.
.

The number of successful attempts to vary, but always limited. Why?
I think this is a SDL error.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

There’s a mention to a related bug in that barren land that is the Android bug tracker. http://code.google.com/p/android/issues/detail?id=2123
It was closed in May 2009, but there’s a comment stating that the issue was present as of March 2010…perhaps it is still there, or perhaps you are using an old NDK/Android version?------------------------
Gabriel Jacobo
mdqinc.com

I submitted a fix for this issue here: http://bugzilla.libsdl.org/show_bug.cgi?id=1417 Can you try it out?------------------------
Gabriel Jacobo
mdqinc.com

Sam Lantinga wrote:

Does the Java VM garbage collection need to kick in to actually close the file references?

Yes, kick it would be nice.

gabomdq wrote:

It was closed in May 2009, but there’s a comment stating that the issue was present as of March 2010…perhaps it is still there, or perhaps you are using an old NDK/Android version?

r7

gabomdq wrote:

I submitted a fix for this issue here: http://bugzilla.libsdl.org/show_bug.cgi?id=1417 Can you try it out?

I picked up a copy of the SDL library a couple of days ago, so:

Code:
hg clone http://hg.libsdl.org/SDL

In my file SDL_android.cpp has the following lines:

Code:

.
.
.
bool allocatedLocalFrame = false;

if (mEnv->PushLocalFrame(16) < 0) {
    SDL_SetError("Failed to allocate enough JVM local references");
    goto failure;
} else {
    allocatedLocalFrame = true;
}
.
.
.
if (allocatedLocalFrame) {
    mEnv->PopLocalFrame(NULL);
}
.

it is a bit like a place where you applied the patch

I submitted a fix for this issue here:
http://bugzilla.libsdl.org/show_bug.cgi?id=1417 Can you try it out?

I picked up a copy of the SDL library a couple of days ago, so:

Code:

hg clone http://hg.libsdl.org/SDL

In my file SDL_android.cpp has the following lines:

Code:

.
.
.
bool allocatedLocalFrame = false;

if (mEnv->PushLocalFrame(16) < 0) {
    SDL_SetError("Failed to allocate enough JVM local references");
    goto failure;
} else {
    allocatedLocalFrame = true;
}
.
.
.
if (allocatedLocalFrame) {
    mEnv->PopLocalFrame(NULL);
}
.

it is a bit like a place where you applied the patch


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

This fixes the file closing function, you are probably looking at the file
open function. I believe the patch should apply cleanly.

gabomdq wrote:

This fixes the file closing function, you are probably looking at the file open function. I believe the patch should apply cleanly.

sorry, hurry)

Yes, your patch has decided my issue. Thank you very much.

Last question: what do these lines in a function of Android_JNI_FileClose ?

2012/2/11 Alexandr

**

gabomdq wrote:

This fixes the file closing function, you are probably looking at the
file open function. I believe the patch should apply cleanly.

sorry, hurry)

Yes, your patch has decided my issue. Thank you very much.

Last question: what do these lines in a function of Android_JNI_FileClose ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

There’s a limit of “local references” for the native code of 512 entries.
The FileClose function was leaking 1 reference per call, and FileOpen tries
to reserve 16 references when it begins, so when you open the 497th file,
it fails (as there’s only 15 spaces left in the table). If you want to
learn more search for Android JNI Local and Global references, there’s
quite a bit of docs online.–
Gabriel.

Thanks to Gabriel and Tim’s efforts, this bug is fixed:

Cheers!On Sat, Feb 11, 2012 at 5:27 PM, Gabriel Jacobo wrote:

2012/2/11 Alexandr

**

gabomdq wrote:

This fixes the file closing function, you are probably looking at the
file open function. I believe the patch should apply cleanly.

sorry, hurry)

Yes, your patch has decided my issue. Thank you very much.

Last question: what do these lines in a function of Android_JNI_FileClose
?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

There’s a limit of “local references” for the native code of 512 entries.
The FileClose function was leaking 1 reference per call, and FileOpen tries
to reserve 16 references when it begins, so when you open the 497th file,
it fails (as there’s only 15 spaces left in the table). If you want to
learn more search for Android JNI Local and Global references, there’s
quite a bit of docs online.


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org