Hi, I’m trying to use native platform to do Base64 decoding for speed reason (believe me it is double the speed on a large string)
The problem is on Android I’m getting this strange error ‘call result code: 0’ and it selectively shows this error.
For example decode a 1.7MB string it works fine, on another 2.2MB string it failed with call result code: 0
Even on a very simple string I can trigger the error 100% of the time.
Below are my JS code to trigger the problem
if(sys.os == cc.sys.OS_ANDROID) cc.log("JSON decode:"+jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "base64Decode", "(Ljava/lang/String;)Ljava/lang/String;", "dGVzdCBzdHJpbmc="));
Below are Java code in AppAcitivity.java
public static String base64Decode(String base64String){
int flags = Base64.NO_WRAP | Base64.URL_SAFE;
byte[] data = Base64.decode(base64String, flags);
String decodedString = new String(data);
//Log.v("AppActivity base64Decode", decodedString);
return decodedString;
}
And then error in the logcat
D/cocos2d-x debug info( 2188): JS: JSON decode:test string
D/cocos2d-x debug info( 2188): JS: touch
D/cocos2d-x debug info( 2188): JS: /Users/userName/Documents/cocos/gameName/frameworks/runtime-src/proj.android/assets/src/app.js:226:Error: js_cocos2dx_JSJavaBridge : call result code: 0
In this instance it actually works by printing cc log and then it returns error on the same line.
On a large string for example picture string it failed to run at all and its very hard to tell why.
Update
CCJavascriptJavaBridge.cpp
Make sure JS_ReportError has if statement in front.
This is already fixed in the latest version of cocos2d-x but I’m using an older version.
Its funny that the return value actually bug out if JS_ReportError get run.