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

Summary: Multi-thread bug on Android caused by global JNIEnv
Product: SDL Reporter: Bill_Chenbin <bingoes>
Component: threadAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: bingoes, icculus
Version: HG 2.0   
Hardware: Other   
OS: Android (All)   
Attachments: Patch for SDL_android.cpp

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.