cc.audioEngine.pause的问题

crash.zip (548.9 KB)

demo来了,请运行helloworld场景,我只在HelloWorld.js里加了

start:function()
{
cc.audioEngine.pause(undefined)
},

2017-08-17T02:22:20.775Z - normal: Simulator:

2017-08-17T02:22:20.775Z - normal: Simulator:

2017-08-17T02:22:20.802Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.803Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.803Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.803Z - normal: Simulator:

2017-08-17T02:22:20.803Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.803Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.804Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.805Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.805Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.805Z - normal: Simulator:

2017-08-17T02:22:20.805Z - normal: Simulator:

2017-08-17T02:22:20.806Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.806Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.806Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.806Z - normal: Simulator:

2017-08-17T02:22:20.806Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.806Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.806Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.807Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.807Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.807Z - normal: Simulator:

2017-08-17T02:22:20.807Z - normal: Simulator:

2017-08-17T02:22:20.825Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.825Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.826Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.826Z - normal: Simulator:

2017-08-17T02:22:20.827Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.828Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.828Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.828Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.828Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.829Z - normal: Simulator:

2017-08-17T02:22:20.829Z - normal: Simulator:

2017-08-17T02:22:20.857Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.857Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.857Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.858Z - normal: Simulator:

2017-08-17T02:22:20.858Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.858Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.858Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.859Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.859Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.859Z - normal: Simulator:

2017-08-17T02:22:20.859Z - normal: Simulator:

2017-08-17T02:22:20.860Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.860Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.861Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.861Z - normal: Simulator:

2017-08-17T02:22:20.861Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.861Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.862Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.862Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.862Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.862Z - normal: Simulator:

2017-08-17T02:22:20.862Z - normal: Simulator:

2017-08-17T02:22:20.879Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.879Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.879Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.880Z - normal: Simulator:

2017-08-17T02:22:20.880Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.884Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.884Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.885Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.885Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.885Z - normal: Simulator:

2017-08-17T02:22:20.886Z - normal: Simulator:

2017-08-17T02:22:20.905Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.905Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.906Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.906Z - normal: Simulator:

2017-08-17T02:22:20.906Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.906Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.907Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.907Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.907Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.908Z - normal: Simulator:

2017-08-17T02:22:20.909Z - normal: Simulator:

2017-08-17T02:22:20.909Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.909Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.910Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.910Z - normal: Simulator:

2017-08-17T02:22:20.911Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.911Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.911Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.911Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.911Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.911Z - normal: Simulator:

2017-08-17T02:22:20.911Z - normal: Simulator:

2017-08-17T02:22:20.939Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.939Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.940Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.940Z - normal: Simulator:

2017-08-17T02:22:20.940Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.941Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.941Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.941Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.942Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.942Z - normal: Simulator:

2017-08-17T02:22:20.943Z - normal: Simulator:

2017-08-17T02:22:20.943Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.943Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.943Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.944Z - normal: Simulator:

2017-08-17T02:22:20.944Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.945Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

2017-08-17T02:22:20.945Z - normal: Simulator: [47]</OneOffInvoker<.invoke@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8444:17

2017-08-17T02:22:20.945Z - normal: Simulator: [47]</ComponentScheduler<.startPhase@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:8578:17

2017-08-17T02:22:20.945Z - normal: Simulator: [200]</cc.Director._beforeUpdateListener.callback@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js:34978:17

2017-08-17T02:22:20.945Z - normal: Simulator:

2017-08-17T02:22:20.946Z - normal: Simulator:

2017-08-17T02:22:20.970Z - normal: Simulator: jsb: ERROR: File …\auto\jsb_cocos2dx_audioengine_auto.cpp: Line: 279, Function: js_cocos2dx_audioengine_AudioEngine_pause

2017-08-17T02:22:20.971Z - normal: Simulator: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments

2017-08-17T02:22:20.971Z - normal: Simulator: JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

2017-08-17T02:22:20.971Z - normal: Simulator:

2017-08-17T02:22:20.971Z - normal: Simulator: Stack: start@D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js:24:9

2017-08-17T02:22:20.972Z - normal: Simulator: anonymous@C:/CocosCreator/resources/cocos2d-x/simulator/win32//src/jsb_polyfill.js line 8490 > Function:1:63

看到问题了,你传递了非法参数给 cc.audioEngine.pause,这个是很明确被提示出来的

JS Exception: js_cocos2dx_audioengine_AudioEngine_pause : Error processing arguments, file: D:/projects/bullfight/crash/temp/quick-scripts/assets/Script/HelloWorld.js, lineno: 24

包括出错的代码行数,以及调用栈都用,看到这么明显的错误,只要修正一下代码就可以了。

cc.audioEngine.pause(undefined)

这样的调用不管在 1.5.2 还是在 1.6 中都是非法的调用,我们的 API 文档也很明确

http://cocos.com/docs/creator/api/classes/audioEngine.html#method_pause


至于你说的死循环,原因是 start 函数使用事件机制来驱动,它的代码执行中断,导致 start 函数的事件监听器没有被正确取消,所以一直重复执行,这个我们可以优化一下避免重复执行。

这样的代码早就修正过了,发这个帖,不是为了解决我的这个问题,当时看到只用了不到10秒就解决了,发这个帖,是希望为引擎的健壮性,做那么一点点贡献。
有些参数是在特定的情况下,绕了几个圈它就可能会变成不可预知的值,比如在销毁过程中,当对象很多的时候,销毁的顺序可能导致一些莫名其妙的错误,可能机率很低,但如果在发生这样的错误的时候也不闪退,就完美了。
当然,我在所有cc.audioEngine.pause前都先判断参数是不是undefined,也是可以解决的,目前我也是这样修复的。因为这里只是一个简单的背景音乐,有个开关,开关没打开,这个play不会调用,就没有audioID,就不能pause.

这可能是我们的价值观不同,有这个报错我认为就足够了,并不需要去保护这些可能导致问题的代码,否则就越俎代庖了。
当然,你可以不认同,只是目前为之我们团队内部的共识是没有计划做类似的保护措施

你还真是执着啊:joy:

在这一点上,任何时候我都执着。

作为服务器出身,现在双端写代码的过程是这样的:
1.不允许使用调试
2.只使用binary版本
3.几乎不用代码提示

出了问题去分析代码质量,看代码去解决,写大量的代码保护去避免那可能万分之一可能发生的异常,写了保护性代码说明当前程序员考虑到了那个问题,如果没写,很有可能是思维不严密导致,双端同样的写码过程,服务器目前上线运行没有过任何一次宕机,也几乎没有BUG。唯有客户端,因为cocos的代码不在可控范围。但我们还是坚持不使用调试。但可能要用default版本了,实在没办法。

很多人跟我说写太多保护性代码会影响性能,会影响包体大小,我也只能呵呵,增加的那点包体大小会不会超过1k?10k?而且我看了cocos一些代码,大多数时候是写了保护性代码的,都是有这个意识的,出了问题只是失误了,然后嘴硬,不承认错误。:grin:

1赞

认同啊。。上线之后不可预测的错误,引擎就说我提了错误了。。那是不是我们要把引擎所有的提示看一遍,然后再写代码,否则不知道引擎处理了没有,这对一些新人来说,怎么办?

类似的cc.loadScene那个重复加载的提示,非要暂停提示,然后卡住,你都知道错误,就不能提示了,然后过滤掉,继续运行吗

现在是有提示,但是不影响继续运行啊,你不看提示就是了

咱们能不能就事论事,不用用感觉去讨论问题。

我们并不是完全不做任何保护,我所强调的是反对极端的代码保护,无法赞同你所传达的避免一切的崩溃,保姆式得校验所有输入的可能性这样的观点。这几天论坛中你所提到的 API 设计和参数保护问题,我看到的都一一正面回复了,需要加强的地方我也有同意的,比如 start 中的逻辑执行失败导致重复执行 start,这个我们就建立了 issue。

好,那么现在来说 audioEngine.pause 的参数保护问题。遇到这样开发者随意传递参数的情况,在 C++ 等编译型语言,以及 TypeScript 中都会在编译阶段就指出错误,根本无法运行。而在 JS 这样的弱类型开发语言中,我们的选择是,如果 audioEngine.pause 传递的参数类型错误,就抛出 JS 异常,这在我们看来就是一种保护,开发者看到报错,自然应该处理。可以参考相关的实现

https://github.com/cocos-creator/cocos2d-x-lite/blob/develop/cocos/scripting/js-bindings/auto/jsb_cocos2dx_audioengine_auto.cpp#L279

引擎中还有大量的校验,比如 CCASSERT 的使用,甚至会导致崩溃,这都是保护,为了让开发者及时了解到自己的代码有问题,需要修改。

假设我是开发者,如果我的代码写得有问题,API 使用不正确,我最不希望的就是引擎忽略我的 API 调用继续执行。我写的逻辑自然是有意义的,如果因为引擎的代码保护让逻辑继续执行下去,我可能也不会意识到代码有问题,这有两种结局:第一,这个问题只会影响一些细微的表现问题,开发者可能直接就忽略了。第二,逻辑的细微错误很可能导致后面更严重的其他问题,这种延迟了的错误会更不容易调试,更难找到根本原因。再举个例子,如果开发组和测试组分开,开发组在开发的时候由于运行都顺利(没有黑屏没有宕机,但是表现可能不正确,比如音频没有正确暂停)这个时候开发人员很可能会直接提交给测试。测试组发现了音频没有正确被暂停,再提交 bug 给开发组,是不是比开发组直接从报错信息中发现问题来得效率更低?

开发阶段的黑屏宕机,是再正常不过的,都是必须要解决的。我意识到我们的理念不同,所以不指望说服你,但是我不希望自己坚持的理念被认为是嘴硬不承认错误,更不希望其他开发者片面的看到一种观点而受到误导。

1赞

如果就事论事,cc.audioEngine.pause在这里的处理没有问题,如果是闪退就一定是不对的。
但是这里cc.audioEngine.pause的处理还是有瑕疵。可以在debug版本时抛异常可以,但在release版本我个人的处理会将JSB_PRECONDITION2的实现应该改为输出log.不要让后面的代码无法执行,不过也可以用户加try catch,所以这里这个是达标的,没有问题。如果所有接口都是抛异常报错,其实代码可能会写得很长,因为任何地方都要加try catch.还是值得深究。
如果这里去pause声音无效,在LOG里是能找到答案的。百分百能复现的BUG都不是什么BUG,最麻烦的是那些你可能跑一万次只出现一次的BUG,但如果刚好出现了,也不影响其它所有功能的正常运转。程序员的手误什么的有时都是难免会存在的,但就算出现了,如果能保证在用户层是感觉不到的,用户就会觉得这个东西没有问题。
为什么我们一直用binary,因为我觉得我们是cocos的用户,就好像玩家用我们的app,根本不用知道我们里面怎么实现的,他只关心你这玩意是否稳定,不管我怎么点,怎么操作,你这个玩意都不宕机,不闪退,还能正常运转。

哥们,看你这个评论的风格,工作得有10年以上了吧?:grin:
一个字形容,老而弥坚啊:wink:

这里的处理导致脚本不会继续执行,会黑屏,引擎不会针对每个 API 做特化处理,而是在绑定层对参数错误做统一的报错,并且中断 JS 的执行,你想象的游戏中的错误出现,而用户感知不到只是想象而已,绝大多数 API 调用错误都会导致表现的问题,只是严重与否。而在浏览器中其实也是一样的,JS 代码出错,就中断后面的 JS 代码执行,我们做的不过是再正常不过的错误处理。至于用户层代码写得是不是健壮,错误是必现还是偶发,引擎并不关心,我们只会忠实地报错。要达到你说的怎么玩都不宕机,不闪退,任何游戏引擎都做不到。

:3::3::3::3::3::3:

那样这个 bug 就被掩盖了,但因为逻辑已经错了,可能导致一些连锁的其它问题,最后导致开发团队完全摸不着头脑。
如果真的有修复不了的 bug,也应该是开发者收集到后,自己手动加 try catch 等保护。

确实有这个情况,不过我不打算做保护了。不是因为性能不允许,而是因为加了 try catch 后,调试器无法在出错时立刻断点。会断点在 catch 中(如果重新 throw)或者就只打印 error,这样不方便找到错误的地方。
另外死循环也有助于提醒用户这里已经出错了。否则很多人从不看报错的,到时又来喷引擎有 bug。

可不可以分调试模式和release模式区别对待,调试模式你就让它死循环,release模式就报个Error别让它死循环.

http://forum.cocos.com/t/bug-cocos-creator-1-6/50074/48
我另外一个贴,报了N多宕机,我不知道去哪里加try catch,郁闷.我在所有网络收包处理逻辑时都在外层加了try catch的,只是那些错,我真的无从下手.

那些应该是引擎的 bug,等待引擎修复吧

我还是前面的观点,游戏有 bug,就应该玩不了,甚至 crash。逼着用户重新进入游戏,这样才能获得稳妥的游戏体验。