多谢 已经可以了 没看清 v8是只支持windows的吧 我的是mac 用Safari就没任何问题!
文档在那里,以后大家先看完再反馈问题。
那性能没法做到跟native一样好啊,只能做比较简单的吧
eruda.get(‘console’).config.set(‘displayUnenumerable’, false)
1.7打出来的web-mobile里的main.js里多了这句,是干啥用的,多了陌生的东西,不安心
##发现一个关于使用shader的问题
###环境
1.7.0-beta.2
ios 11,iphone6s, 原生
有一段给shader 传值的代码:
if (cc.sys.isNative) {
var glProgram_state = cc.GLProgramState.getOrCreateWithGLProgram(this._program);
glProgram_state.setUniformFloat(this._iGlobalTime, this._time);//0.5
setUniformFloat 这个方法提示没有,但是cocos模拟器运行正常,1.61没有这个问题
[Error] TypeError: glProgram_state.setUniformFloat is not a function. (In 'glProgram_state.setUniformFloat(this._iGlobalTime, this._time)', 'glProgram_state.setUniformFloat' is undefined)
update (src/project.dev.js:5178)
anonymous (匿名脚本 1(第 2 行))
invoke (src/jsb_polyfill.js:7843)
updatePhase (src/jsb_polyfill.js:7940)
callback (src/jsb_polyfill.js:31944)
JSObjectCallAsFunction
se::Object::call(std::__1::vector<se::Value, std::__1::allocator<se::Value> > const&, se::Object*, se::Value*)
js_EventListenerCustom_create(se::State&)::$_17::operator()(cocos2d::EventCustom*) const
void std::__1::__invoke_void_return_wrapper<void>::__call<js_EventListenerCustom_create(se::State&)::$_17&, cocos2d::EventCustom*>(js_EventListenerCustom_create(se::State&)::$_17&&&, cocos2d::EventCustom*&&)
std::__1::__function::__func<js_EventListenerCustom_create(se::State&)::$_17, std::__1::allocator<js_EventListenerCustom_create(se::State&)::$_17>, void (cocos2d::EventCustom*)>::operator()(cocos2d::EventCustom*&&)
std::__1::function<void (cocos2d::EventCustom*)>::operator()(cocos2d::EventCustom*) const
cocos2d::EventListenerCustom::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<void (cocos2d::EventCustom*)> const&)::$_0::operator()(cocos2d::Event*) const
void std::__1::__invoke_void_return_wrapper<void>::__call<cocos2d::EventListenerCustom::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<void (cocos2d::EventCustom*)> const&)::$_0&, cocos2d::Event*>(cocos2d::EventListenerCustom::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<void (cocos2d::EventCustom*)> const&)::$_0&&&, cocos2d::Event*&&)
std::__1::__function::__func<cocos2d::EventListenerCustom::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<void (cocos2d::EventCustom*)> const&)::$_0, std::__1::allocator<cocos2d::EventListenerCustom::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<void (cocos2d::EventCustom*)> const&)::$_0>, void (cocos2d::Event*)>::operator()(cocos2d::Event*&&)
std::__1::function<void (cocos2d::Event*)>::operator()(cocos2d::Event*) const
cocos2d::EventDispatcher::dispatchEvent(cocos2d::Event*)::$_2::operator()(cocos2d::EventListener*) const
bool std::__1::__invoke_void_return_wrapper<bool>::__call<cocos2d::EventDispatcher::dispatchEvent(cocos2d::Event*)::$_2&, cocos2d::EventListener*>(cocos2d::EventDispatcher::dispatchEvent(cocos2d::Event*)::$_2&&&, cocos2d::EventListener*&&)
std::__1::__function::__func<cocos2d::EventDispatcher::dispatchEvent(cocos2d::Event*)::$_2, std::__1::allocator<cocos2d::EventDispatcher::dispatchEvent(cocos2d::Event*)::$_2>, bool (cocos2d::EventListener*)>::operator()(cocos2d::EventListener*&&)
std::__1::function<bool (cocos2d::EventListener*)>::operator()(cocos2d::EventListener*) const
cocos2d::EventDispatcher::dispatchEventToListeners(cocos2d::EventDispatcher::EventListenerVector*, std::__1::function<bool (cocos2d::EventListener*)> const&)
cocos2d::EventDispatcher::dispatchEvent(cocos2d::Event*)
cocos2d::Director::drawScene()
cocos2d::Director::mainLoop()
-[CCDirectorCaller doCaller:]
-[DYDisplayLinkInterposer forwardDisplayLinkCallback:]
<redacted>
IODispatchCalloutFromCFMessage
<redacted>
<redacted>
<redacted>
<redacted>
CFRunLoopRunSpecific
GSEventRunModal
UIApplicationMain
main
<redacted>
1.使用cocos 模拟器 运行,safari调试也出现莫名的崩溃,连safari的开发工具也一块崩溃了,看到崩溃前也是我调用shader地方,但是没有日志.safari的开发工具直接崩掉了.
2.ios 真机出错如上图
这里是换方法了吗
应该不会啊,1.61都跑的好好的.
你调试看看,这个glProgram_state是不是为null啊。
这个不好推断原因了,你整理个复现demo给我吧。
ok,我刚把shader渲染的部分去掉,就没问题了,应该是渲染这的问题.我弄个demo.
我的filepath是这个:
/Applications/CocosCreator 2.app/Contents/Resources/cocos2d
是不是因为这个路径有空格的关系啊?因我安装了两个版本,1.7是后安装的,jsb.fileUtils.getWritablePath() 获得这个路径
去掉空格试试。
弄了个简单的demo,但并没能重现这个问题,但在我的项目里的确是这里出的问题,另外,发现我加的shader,在iphone上运行一会儿就看着非常卡.大神帮忙看看,给点建议. @dumganhar Effect.zip (617.3 KB)
发现两个问题:
- 你写的shader问题不大,主要在JS代码的使用,JS代码对GLProgramState的获取效率低下
- 查你这个demo过程中,发现一个一直以来JSB都存在的一个bug,我建了一个issue: https://github.com/cocos-creator/cocos2d-x-lite/issues/897
优化建议和隐藏bug修复,明天提供。
filepath去掉空格也不行。应该还是data的问题吧,同样的代码之前的所有版本都没有问题,1.7就报错
1.7beta2,web模式,如果preloadScene了,那么再loadScene的话就报错,说已经load过了,无法切换场景,beta1是可以切换的
你看下源码:
bool FileUtils::writeDataToFile(const Data& data, const std::string& fullPath)
{
size_t size = 0;
const char* mode = "wb";
CCASSERT(!fullPath.empty() && data.getSize() != 0, "Invalid parameters.");
...
return false;
}
应该是你传入的path为空,或者是你的data为空了。我怀疑是data为空。你在写入前,打印下data的大小。
问题1:频繁调用cc.GLProgramState.getOrCreateWithGLProgram(this._program);
在每帧update回调的时候都去获取GLProgramState,定义的var glProgram_state
是临时对象,每帧都可能被GC,这个是由于问题2的bug导致的,虽然问题2解决了这个问题,但是还是没必要每帧去调用一个JSB绑定函数获取GLProgramState,完全可以在初始化的时候保存一个GLProgramState对象放在当前class中。在update的时候直接用这个JS对象即可。
问题2:引擎层的Node::setGLProgramState没有对GLProgramState进行脚本层对象的retain,release操作。
setProgram: function (node, program) {
if (cc.sys.isNative) {
var glProgram_state = cc.GLProgramState.getOrCreateWithGLProgram(program); // 创建临时对象
node.setGLProgramState(glProgram_state); // 设置完后,临时对象可在任意时刻被GC,而update中又频繁获取state,导致JS频繁创建这个对象。
} else {
node.setShaderProgram(program);
}
},
问题2的修复PR:https://github.com/cocos-creator/cocos2d-x-lite/pull/898
1.7beta2 直接使用拖拽地图 map.tmx 报错 无法添加 例子内也都无法拖拽 原来可以用的项目也报错。。
TypeError: Cannot read property ‘width’ of undefined
at TheClass._fillTextureGrids (/Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/tilemap/CCSGTMXLayer.js:133:38)
at TheClass.initWithTilesetInfo (/Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/tilemap/CCSGTMXLayer.js:215:22)
at TheClass.ctor (/Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/tilemap/CCSGTMXLayer.js:109:18)
at new TheClass (/Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/core/platform/_CCClass.js:98:34)
at TheClass._parseLayer (/Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/tilemap/CCSGTMXTiledMap.js:403:21)
at TheClass._buildWithMapInfo (/Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/tilemap/CCSGTMXTiledMap.js:305:34)
at TheClass.initWithXML (/Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/tilemap/CCSGTMXTiledMap.js:278:14)
at cc_TiledMap._applyFile (/Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/tilemap/CCTiledMap.js:856:30)
at cc_TiledMap.set (/Applications/CocosCreator.app/Contents/Resources/engine/cocos2d/tilemap/CCTiledMap.js:256:26)
at cc_TiledMap.r.set [as tmxAsset] (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor/page/scene-utils/asset-watcher.js:1:766)