cc.audioEngine.pause的问题

cc.audioEngine.pause如果传入的是undefined,刚好这个又写在onDisable里,就会出现死循环,我个人不能忍受这个,如果觉得没什么问题就忽略吧。

我本来想喷:为什么不效验传进来的参数的合法性?而且1.5.2这样调用是没有问题的。

引擎升得我有点心虚呀,后面我给出一些性能指标和BUG。
升过的引擎,再苦也要把坑踩完。。。

…为什么会死循环? audioEngine 和 node 是不相关的,所以不会触发到什么 onDisable 的方法吖?
是不是其他什么问题引起的。

能不能说一下具体的还原方法哦,能有个小 demo 最好啦。如果能还原定位问题的话,肯定第一时间修复并给大家一个答复哇。

还有~关于校验参数的问题,是这样的,现在大部分接口都没校验,只是会尽量保证传错了表现也正常,或者会有相关看得出问题的调用栈来定位问题,如果所有 api 全部校验并增加提醒语句的话,引擎包体又会大很多,所以只有部分重要的会引起自身报错之外的问题的我们会做一些限制。

这个出现死循环跟我之前在start里面调用出现代码错误是同一个问题,就是引擎层的发生错误后不断去调用那个代码,之前在start里面只要有代码错误就会出现死循环。

cc.audioEngine.pause(undefined)就出现了代码错误,然后就死循环了,等一下,我弄个demo.

cc.audioEngine.pause 会返回一个 boolean,如果正常找到了 audio 并且暂停了,会返回 true,如果找不到音频,则会返回 false。并不会出错哦。

恩啊,谢谢啦~~~

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: