android 5.1 真机错误( Failed to invoke SocketIO_emit)

12-05 09:38:11.673 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:13.067 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:16.671 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:21.678 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:25.676 32569-32679/cn.channel8.mjgame E/CocosAnalytics: ==> Please init sdk first!
12-05 09:38:25.676 32569-32679/cn.channel8.mjgame E/CocosAnalytics: ==> checkAndUploadLog, database is not open!
12-05 09:38:26.670 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:31.674 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:36.662 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:41.674 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:46.679 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:51.667 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:38:52.708 32569-32656/cn.channel8.mjgame I/libGameXtend: LUCID_1 (1512437932707) GameXtend is currently running in Automatic mode
12-05 09:38:52.708 32569-32656/cn.channel8.mjgame I/libGameXtend: LUCID_1 (1512437932708) GameXtend is currently running in no_save Save power state.
12-05 09:38:52.708 32569-32656/cn.channel8.mjgame I/libGameXtend: LUCID_1 (1512437932708) cn.channel8.mjgame is currently running with GameXtend, with PS parameter = 1. , Ice parameter = 0. PS parameter source is PowerXtend configuration
12-05 09:38:52.708 32569-32656/cn.channel8.mjgame I/libGameXtend: LUCID_1 (1512437932708) PowerXtend touch feature is not active
12-05 09:38:55.677 32569-32679/cn.channel8.mjgame E/CocosAnalytics: ==> Please init sdk first!
12-05 09:38:55.677 32569-32679/cn.channel8.mjgame E/CocosAnalytics: ==> checkAndUploadLog, database is not open!
12-05 09:38:56.674 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:39:01.675 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203
12-05 09:39:06.670 32569-32656/cn.channel8.mjgame E/jswrapper: [ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/proj.android/…/manual/jsb_socketio.cpp:203

sb: ERROR: File /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/manual/jsb_socketio.cpp: Line: 192, Function: SocketIO_emit
Converting payload failed!
[ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/manual/jsb_socketio.cpp:203
jsb: ERROR: File /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/manual/jsb_socketio.cpp: Line: 192, Function: SocketIO_emit
Converting payload failed!
[ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/manual/jsb_socketio.cpp:203
JS: onBtnReadyClicked
jsb: ERROR: File /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/manual/jsb_socketio.cpp: Line: 192, Function: SocketIO_emit
Converting payload failed!
[ERROR] Failed to invoke SocketIO_emit, location: /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/manual/jsb_socketio.cpp:203
jsb: ERROR: File /Users/nantas/fireball-x/cocos2d-x-lite-prebuilt/cocos/scripting/js-bindings/manual/jsb_socketio.cpp: Line: 192, Function: SocketIO_emit
Converting payload failed!
问题没有找到,cocos creator 1.7 生产项目有问题吧,我mac 用户是Sjw,没有 /Users/nantas/这个目录呢?

1赞

1.7.0以上版本都有问题,socket发送数据不带数据

没看懂。

this.sio.emit(event); 1.7.0以前版本发送数据方式正常,现在这段代码放在1.7.0以后版本会出现上面错误

你这是胡说啊。看1.6中的代码:

bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, JS::Value* vp)
{
    CCLOG("JSB SocketIO.emit method called");

    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
    js_proxy_t *proxy = jsb_get_js_proxy(cx, obj); 
    SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");

    if (argc == 2) // 看这里,必须要两个参数,如果你只传一个eventname,那么这个逻辑是直接报JSB SocketIO.emit: Wrong number of arguments的
    {
        std::string eventName;
        do
        {
            bool ok = jsval_to_std_string(cx, args.get(0), &eventName);
            JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
        } while (0);
        
        std::string payload;
        do {
            bool ok = jsval_to_std_string(cx, args.get(1), &payload);
            JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
        } while (0);

        CCLOG("JSB SocketIO emit event '%s' with payload: %s", eventName.c_str(), payload.c_str());

        cobj->emit(eventName, payload);
        return true;
    }
    JS_ReportErrorUTF8(cx, "JSB SocketIO.emit: Wrong number of arguments");
    return false;
}

看我上面注释。

不过这的确是个问题。我稍后修复。但这不是1.7引入的问题。是一直以来就有的问题。

这样做,没有问题,只是以前代码要修改下

我晕,1.6中直接把 undefined转换为空字符串了。
理论上不应该是空的,按照js标准,undefined强制转换为字符串,应该是字符串“undefined”的。

bool jsval_to_std_string(JSContext *cx, JS::HandleValue v, std::string* ret) {
    if (v.isString())
    {
        JS::RootedString tmp(cx, v.toString());
        JSB_PRECONDITION3(tmp, cx, false, "Error processing arguments");

        JSStringWrapper str(tmp);
        *ret = str.get();
    }
    else if (v.isBoolean())
    {
        *ret = v.toBoolean() ? "true" : "false";
    }
    else if (v.isInt32())
    {
        char buff[20];
        snprintf(buff, sizeof(buff), "%d", v.toInt32());
        *ret = buff;
    }
    else if (v.isNumber())
    {
        char buff[20];
        snprintf(buff, sizeof(buff), "%.2f", v.toNumber());
        *ret = buff;
    }
    else if (v.isNullOrUndefined()) 
    {
        *ret = ""; // 看这里。
    }
    else
    {
        return false;
    }

    return true;
}

我打脸了。

engine仓库居然有这样的代码:

https://github.com/cocos-creator/engine/blob/v1.7-release/jsb/jsb-etc.js#L142

所以c++这层,固定是传递了两个参数,如果没有第二个参数,默认是补上undefined的。
而1.6的jsval_to_std_string 把 undefined转换为“”,这个行为是错误的。
我想想如何处理吧。

解决方案:

https://github.com/cocos-creator/cocos2d-x-lite/pull/1019

你自己可以先改一下。

1赞

不知道楼主还会不会看消息 我在学习大佬的源码但是现在就到创建房间进不去游戏 不知道该怎么办 求指教