We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1814 - SDL_RWFromFile check for existance leads to crash
Summary: SDL_RWFromFile check for existance leads to crash
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: file (show other bugs)
Version: HG 2.0
Hardware: ARM Android (All)
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-19 04:02 UTC by Martin Gerhardy
Modified: 2013-05-21 03:46 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Gerhardy 2013-04-19 04:02:06 UTC
Whenever i call SDL_RWFromFile to check whether a file exists, but it does not exist, i get a crash like this one.

I/DEBUG   (  125): backtrace:
I/DEBUG   (  125):     #00  pc 00045c90  /system/lib/libdvm.so (dvmAbort+75)
I/DEBUG   (  125):     #01  pc 000285ec  /system/lib/libdvm.so (IndirectRefTable::get(void*) const+336)
I/DEBUG   (  125):     #02  pc 0004a225  /system/lib/libdvm.so (dvmDecodeIndirectRef(Thread*, _jobject*)+80)
I/DEBUG   (  125):     #03  pc 0004cd83  /system/lib/libdvm.so
I/DEBUG   (  125):     #04  pc 00072670  /data/app-lib/org.myapp-1/libSDL2.so (_JNIEnv::GetObjectClass(_jobject*)+40)
I/DEBUG   (  125):     #05  pc 00076678  /data/app-lib/org.myapp-1/libSDL2.so (SDL_AndroidGetInternalStoragePath+316)
I/DEBUG   (  125):     #06  pc 000806bc  /data/app-lib/org.myapp-1/libSDL2.so (SDL_RWFromFile+224)
Comment 1 Martin Gerhardy 2013-04-19 04:14:49 UTC
If I change

#if defined(ANDROID)
#ifdef HAVE_STDIO_H

in SDL_RWFromFile

to

#if defined(ANDROID)
#if 0

it works.
Comment 2 Martin Gerhardy 2013-04-19 04:54:45 UTC
SDL_AndroidGetInternalStoragePath

mid = env->GetMethodID(env->GetObjectClass(fileObject),
                "getAbsolutePath", "()Ljava/lang/String;");

this line leads to

W/dalvikvm(27162): Exception thrown (Ljava/lang/NoSuchMethodError;) while throwing internal exception (Ljava/lang/NoSuchMethodError;)
E/dalvikvm(27162): JNI ERROR (app bug): attempt to use stale global reference 0x1a
E/dalvikvm(27162): VM aborting
Comment 3 Gabriel Jacobo 2013-04-19 13:04:35 UTC
Does this happen on a newish Android? (4.x) I've seen something quite like this happen with the audio buffers, which were allocated on the Java side and passed to the C side. Something changed in Android 4.x that made this sort of code where an object is returned fail (in this case I think fileObject is the problem).

The workaround I used was allocating the audio buffer on the C side directly, but it seems in this case a proper fix will be needed.
Comment 4 Gabriel Jacobo 2013-04-22 10:09:42 UTC
I could not reproduce this on Android 4.2. I tried opening a non existent file, existing files, etc, SDL_AndroidGetInternalStoragePath runs once and returns /data/data/<package>/files, after that it just returns the interally stored static string.

Can you provide more information about your system? Android version, device, are you using threads, etc?
Comment 5 Martin Gerhardy 2013-04-23 02:54:07 UTC
I will check on the weekend - thanks a lot for also looking into it. I will try to provide some more information. Btw. I also had SDL_AndroidGetActivity problem with the references - maybe this was related somehow?
Comment 6 Gabriel Jacobo 2013-05-18 19:18:51 UTC
Any luck?
Comment 7 Martin Gerhardy 2013-05-21 01:50:32 UTC
I'm not able to reproduce this anymore - but I've updated my system and the ndk. I'm also building for a new android target. So it might already be fixed or might be some old android-** target problem. For me it works now and is no longer a problem.
Comment 8 Sam Lantinga 2013-05-21 03:46:54 UTC
Okay, thanks for the update.
Please feel free to reopen this bug if you find that it's not fixed.