bearcatjs / bearcat

powered by enhanced javaScript objects
http://bearcatjs.org/
Other
591 stars 110 forks source link

bearcat is not working with cocos2d-js(3.6.1)! #194

Closed zj8487 closed 8 years ago

zj8487 commented 9 years ago

it says there is error in main.js which is generator by bearcat grunt!

i guess the require is changed, so bearcat need change too.

error output:

D/cocos2d-x debug info(23941): script:main.js
D/cocos2d-x debug info(23941): (evaluatedOK == JS_FALSE)

the output above is from follow:

bool ScriptingCore::runScript(const char *path, JS::HandleObject global, JSContext* cx)
{
    if (cx == NULL) {
        cx = _cx;
    }

    compileScript(path,global,cx);
    JS::RootedScript script(cx, getScript(path));
    bool evaluatedOK = false;
    if (script) {
        JS::RootedValue rval(cx);
        JSAutoCompartment ac(cx, global);
        evaluatedOK = JS_ExecuteScript(cx, global, script, &rval);
        if (false == evaluatedOK) {
            cocos2d::log("script:%s", path);
            cocos2d::log("(evaluatedOK == JS_FALSE)");
            JS_ReportPendingException(cx);
        }
    }

    return evaluatedOK;
}
zj8487 commented 9 years ago

just not work on the real android device! so first package an app and install and adb log

fantasyni commented 9 years ago

require used in main.js is in closure, it will not be confused with cocos2d-js require

zj8487 commented 9 years ago

but it woks cocos2d-js 3.5~~~~` how can i do to make it work?

zj8487 commented 9 years ago

i will try to make all require in closure today. and feedback

zj8487 commented 9 years ago

this is my app.js for bearcat. and all the other dependency is migrate to requireUtil.js , but it still not woks.

require('./bearcat-bootstrap.js');
require('pomelo-cocos2d-js');

var Promise = require('promise');
var bearcat = require('bearcat');
window.bearcat = bearcat;
window.Promise = Promise;

cc.game.onStart = function() {
    cc.view.adjustViewPort(true);
    cc.view.setDesignResolutionSize(960, 640, cc.ResolutionPolicy.EXACT_FIT);
    cc.view.resizeWithBrowserSize(true);
    cc.director.setProjection(cc.Director.PROJECTION_2D);

    cc.loader.resPath = "res/images/";
    cc.loader.audioPath = "res/audio/";

    var self = this;
    bearcat.createApp();
    require('./src/util/requireUtil');
    if (cc.sys.isNative != true) {
        bearcat.use(Object.keys(__bearcatData__.idPaths));
    }
    bearcat.start(function() {
        // deleted for private
        }, self);
    });

};

cc.game.run();
fantasyni commented 9 years ago

ok i will test on cocos2d-js 3.6.x version

zj8487 commented 9 years ago

it works on adb debug model but not work when you install the package on device!

zj8487 commented 9 years ago

ping

fantasyni commented 9 years ago

这个问题是因为 cocos2d-js 在 android 打包的 spidermonkey 有bug
主要出现在 require('xxx') 时,这个如果不存在应该丢出异常,但是有bug的话,就只返回那句
在browserify里面,需要用到require,可以进行hack处理

fileStr = fileStr.replace(/typeof\s*require==\"function\"\&\&require/g, "function(str) {throw new Error('can not require ' + str)}");

把打包出来的browserify文件,替换一下里面的require就行了

zj8487 commented 9 years ago

这都被你查到,厉害!

fantasyni commented 9 years ago

我也找了一天才发现,它在windows下面也有这个bug的,不过3.6.1版本的貌似修复了