[Help]Cocos2dxLuaJavaBridge调用LUA回调出错

调用代码:从ui线程中调用如下静态类

static void callLuaLogin(final String accessToken) {
runOnGLThread(new Runnable() {
@Override
public void run() {
Log.d(TAG, “call lua function loginResultCallback”);
Cocos2dxLuaJavaBridge.callLuaFunctionWithString(loginResultCallback, accessToken);
}
});
}

08-18 20:44:34.522: D/FacebookBridge(15862): call lua function loginResultCallback
08-18 20:44:34.522: E/dalvikvm(15862): JNI ERROR (app bug): attempt to use stale local reference 0x1
08-18 20:44:34.522: E/dalvikvm(15862): VM aborting
08-18 20:44:34.522: A/libc(15862): Fatal signal 6 (SIGABRT) at 0x00003df6 (code=-6), thread 16135 (Thread-4105)

quick-cocos2d-x版本https://github.com/chukong/quick-cocos2d-x上的最新master分支

大神们帮忙看看,看起来像JNI调用出错了


问题解决了,其实这个调用是成功了的,不过lua的回调里接着调用了getUDID方法,而PSNative没初始化直接挂了,日志上看不出什么错误,上android单步调试才发现接着进入了PSNative里,寒

把LuaJavaBridge调用的日志贴上来

08-18 21:05:17.392: V/MediaPlayer(24712): decode(66, 540252, 4244)
08-18 21:05:17.422: V/MediaPlayer(24712): decode(71, 481401, 804)
08-18 21:05:35.282: D/cocos2d-x debug info(24712): luaj.callStaticMethod(“com/cfunctions/cocoslib/facebook/FacebookBridge”, ====>这里LUA调用JAVA
08-18 21:05:35.282: D/cocos2d-x debug info(24712): “login”,
08-18 21:05:35.282: D/cocos2d-x debug info(24712): args,
08-18 21:05:35.282: D/cocos2d-x debug info(24712): “(I)V”
08-18 21:05:35.282: D/luajc(24712): CCLuaJavaBridge::callJavaStaticMethod(lua_State *L)
08-18 21:05:35.282: D/LUALOG(24712): luaj.callStaticMethod(“com/cfunctions/cocoslib/facebook/FacebookBridge”,
08-18 21:05:35.282: D/LUALOG(24712): “login”,
08-18 21:05:35.282: D/LUALOG(24712): args,
08-18 21:05:35.282: D/LUALOG(24712): “(I)V”
08-18 21:05:35.282: D/luajc(24712): CCLuaJavaBridge::callJavaStaticMethod(“android/util/Log”, “d”, args, “(Ljava/lang/String;Ljava/lang/String;)I”) SUCCESS
08-18 21:05:35.282: D/luajc(24712): CCLuaJavaBridge::callJavaStaticMethod(lua_State *L)
08-18 21:05:35.282: D/FacebookBridge(24712): login =====>这里成功调用到java方法开始执行登录GL线程
08-18 21:05:35.282: D/luajc(24712): luajretainLuaFunctionById(1) - retain count = 2
08-18 21:05:35.282: D/luajc(24712): CCLuaJavaBridge::callJavaStaticMethod(“com/cfunctions/cocoslib/facebook/FacebookBridge”, “login”, args, “(I)V”) SUCCESS
08-18 21:05:35.282: D/FacebookBridge(24712): plug login ==>UI线程
08-18 21:05:35.282: D/FacebookPlugin(24712): login
08-18 21:05:35.292: D/FacebookBridge(24712): call lua function loginResultCallback ==>登录成功,回调LUA传回access_token GL线程
08-18 21:05:35.292: E/dalvikvm(24712): JNI ERROR (app bug): attempt to use stale local reference 0x1 ==>报错
08-18 21:05:35.292: E/dalvikvm(24712): VM aborting
08-18 21:05:35.292: A/libc(24712): Fatal signal 6 (SIGABRT) at 0x00006088 (code=-6), thread 24730 (Thread-4846)

java方法要在 UI 线程里跑。你检查一下这里。

看最后的错误信息应该是 lua vm 已经因为跨线程原因被搞坏了。

请教楼主,我为啥用lua调java就提示 :0: attempt to index global ‘LuaJavaBridge’ (a nil value)

请楼主无视上面的问题,已解决

你好,新手一个,想用lua调用java后台接口,查了一些资料,有点乱,可否指点一下,我本地的环境是cocoa Ide + Quick-Cocos2d-x + lua?还需要其他什么的吗?多谢了