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 1312 - Multi-thread bug on Android caused by global JNIEnv
Summary: Multi-thread bug on Android caused by global JNIEnv
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: thread (show other bugs)
Version: HG 2.0
Hardware: Other Android (All)
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-10 22:34 UTC by Bill_Chenbin
Modified: 2011-10-26 05:55 UTC (History)
2 users (show)

See Also:


Attachments
Patch for SDL_android.cpp (5.07 KB, patch)
2011-10-10 22:34 UTC, Bill_Chenbin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bill_Chenbin 2011-10-10 22:34:11 UTC
Created attachment 711 [details]
Patch for SDL_android.cpp

Problem:
The JNI environment is unique for each thread, so if there is multiple native threads (such as video and audio thread) the using of global JNIEnv will cause the program to crash.

Resolve method:
The JavaVM pointer, on the other hand, is per-program, so can be cached in the JNI_OnLoad() function, and safely used across threads.
(Ref: http://android.wooyd.org/JNIExample/files/JNIExample.pdf)

Please see the attached patch for SDL_android.cpp
After this fix FFplay (using SDL) can work normally on Android.
Comment 1 Ryan C. Gordon 2011-10-15 23:51:18 UTC
A variation on this patch is now hg changeset 102a9ec1ea13, thanks!

--ryan.
Comment 2 Bill_Chenbin 2011-10-26 05:55:29 UTC
You are welcome~
(In reply to comment #1)
> A variation on this patch is now hg changeset 102a9ec1ea13, thanks!
> 
> --ryan.