Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifecycle: always call start, update, lateUpdate in try catch #4941

Merged
merged 1 commit into from Jul 31, 2019

Conversation

@jareguo
Copy link
Contributor

commented Jul 22, 2019

https://forum.cocos.com/t/2-0-10-start/80547
实际上就算 start 不再重复调用了,用户的游戏也是很有可能出错的,因为逻辑未能完整初始化。这里只能防止频繁报同一个错误,方便用户调试(未必)。

so that user defined start will not be invoked repeatedly when exception occur
@jareguo jareguo force-pushed the jareguo:v2.1.3 branch from 2029698 to 2ace251 Jul 22, 2019
@jareguo jareguo changed the title Lifecycle: user defined start should not be invoked repeatedly when exception occur Lifecycle: always call start, update, lateUpdate in try catch Jul 22, 2019
@@ -215,47 +212,65 @@ function enableInEditor (comp) {
}
}

function createInvokeImpl (funcOrCode, useDt) {
// return function to simply call each component with try catch protection
function createInvokeImpl (funcOrCode, useDt, ensureFlag) {

This comment has been minimized.

Copy link
@jareguo

jareguo Jul 22, 2019

Author Contributor

把之前各种复杂的逻辑集中到 createInvokeImpl 内部了。其它地方看起来简洁很多。

}
return function (iterator, dt) {
try {
fastPath(iterator, dt);

This comment has been minimized.

Copy link
@jareguo

jareguo Jul 22, 2019

Author Contributor

分为正常和保护两种模式,确保在不抛异常时游戏性能不因为保护代码受到影响

@jareguo jareguo requested a review from 2youyou2 Jul 22, 2019
@jareguo

This comment has been minimized.

Copy link
Contributor Author

commented Jul 23, 2019

之后所有 onLoad(场景初始化阶段) / start / update / lateUpdate 都会做 try catch 保护,其它生命周期回调目前没有类似处理,因为比较复杂,弄不好会影响性能

@2youyou2 2youyou2 merged commit 67835b9 into cocos-creator:v2.1.3 Jul 31, 2019
1 check passed
1 check passed
ci/circleci: test Your tests passed on CircleCI!
Details
jareguo added a commit that referenced this pull request Aug 2, 2019
* commit 'a3de003db47b4afa537a97b829ad75069f48be95':
  fix browser breaking when playing audio on uc browser (#5048)
  fix vec2、vec3、vec4 parameters type error (#5064)
  Fix call node targetOff func has not remove node from target.__eventTargets array (#5052)
  add play and stop sub particle for editor mode (#5031)
  fix IE11's not supporting to Array.includes (#5033)
  fix issue #4942
  BUG FIX: audio fail to register touch event listener && fix audio loading (#4991)
  fix ecScene null (#5000)
  Lifecycle: always call start, update, lateUpdate in try catch (#4941)
  Fix a memory leak caused by the render-data not being properly released! (#5025)
  avoid releasing builtin asset (#4915)
  fix auto sync prefab rotation and z invalid (#4975)
  revert fix pageview inertia invalid (#4945) (#4968)
  refine code (#4964)
  fix pageview inertia invalid (#4945)

# Conflicts:
#	cocos2d/audio/CCAudio.js
#	cocos2d/core/graphics/graphics.js
#	cocos2d/core/load-pipeline/audio-downloader.js
#	cocos2d/core/platform/CCSys.js
#	cocos2d/core/renderer/index.js
#	cocos2d/core/utils/prefab-helper.js
#	cocos2d/renderer/render-data/render-data.js
#	cocos2d/tilemap/CCTiledMap.js
@ETRick

This comment has been minimized.

Copy link

commented Sep 27, 2019

微信上有办法抓到内部的UnhandledRejection错误吗

@jareguo

This comment has been minimized.

Copy link
Contributor Author

commented Sep 27, 2019

目前请直接调用微信 api 抓取

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.