创建两个场景,在两个场景间频繁切换(一般快速切换5到6次就出现),程序崩溃
崩溃日志:
CCScale9Sprite.js:1240 Uncaught TypeError: Cannot read property ‘height’ of null
at TheClass.setContentSize (CCScale9Sprite.js:1240)
at onResourceDataLoaded (CCScale9Sprite.js:1198)
at TheClass.setSpriteFrame (CCScale9Sprite.js:1204)
at cc_Sprite._onTextureLoaded (CCSprite.js:540)
at cc_Sprite._applySpriteFrame (CCSprite.js:559)
at cc_Sprite._initSgNode (CCSprite.js:584)
at cc_Sprite.__preload (CCRendererUnderSG.js:60)
at CCClass.eval [as _invoke] (eval at createInvokeImpl (component-scheduler.js:255),
65)
at CCClass.invoke (node-activator.js:65)
at CCClass.activateNode (node-activator.js:225)
setContentSize @ CCScale9Sprite.js:1240
onResourceDataLoaded @ CCScale9Sprite.js:1198
setSpriteFrame @ CCScale9Sprite.js:1204
_onTextureLoaded @ CCSprite.js:540
_applySpriteFrame @ CCSprite.js:559
_initSgNode @ CCSprite.js:584
__preload @ CCRendererUnderSG.js:60
(anonymous) @ VM30357:3
invoke @ node-activator.js:65
activateNode @ node-activator.js:225
_activate @ CCScene.js:96
runSceneImmediate @ CCDirector.js:615
(anonymous) @ CCDirector.js:832
(anonymous) @ CCAssetLibrary.js:110
(anonymous) @ CCLoader.js:255
(anonymous) @ utils.js:85
setTimeout (async)
callInNextTick @ utils.js:84
(anonymous) @ CCLoader.js:251
139.proto.allComplete @ loading-items.js:527
139.proto.append @ loading-items.js:504
130.proto.load @ CCLoader.js:274
loadAsset @ CCAssetLibrary.js:90
_loadSceneByUuid @ CCDirector.js:807
loadScene @ CCDirector.js:739
(anonymous) @ ExternInterface.ts:658
(anonymous) @ CCDirector.js:773
(anonymous) @ CCLoader.js:255
(anonymous) @ utils.js:85
setTimeout (async)
callInNextTick @ utils.js:84
(anonymous) @ CCLoader.js:251
139.proto.allComplete @ loading-items.js:527
139.proto.itemComplete @ loading-items.js:715
139.LoadingItems.itemComplete @ loading-items.js:378
142.proto.flowOut @ pipeline.js:318
(anonymous) @ pipeline.js:66
(anonymous) @ uuid-loader.js:172
(anonymous) @ CCLoader.js:298
139.proto.allComplete @ loading-items.js:527
139.proto.append @ loading-items.js:504
130.proto.flowInDeps @ CCLoader.js:309
loadDepends @ uuid-loader.js:111
loadUuid @ uuid-loader.js:274
138.Loader.handle @ loader.js:151
flow @ pipeline.js:50
(anonymous) @ pipeline.js:63
(anonymous) @ downloader.js:327
xhr.onload @ text-downloader.js:45
load (async)
144.module.exports @ text-downloader.js:42
downloadUuid @ downloader.js:196
135.Downloader.handle @ downloader.js:324
flow @ pipeline.js:50
(anonymous) @ pipeline.js:63
(anonymous) @ asset-loader.js:81
queryAssetInfo @ CCAssetLibrary.js:182
131.AssetLoader.handle @ asset-loader.js:47
flow @ pipeline.js:50
142.proto.flowIn @ pipeline.js:274
139.proto.append @ loading-items.js:507
130.proto.load @ CCLoader.js:274
preloadScene @ CCDirector.js:768
(anonymous) @ ExternInterface.ts:656
step @ typescript.js:68
(anonymous) @ typescript.js:49
fulfilled @ typescript.js:40
Promise.then (async)
step @ typescript.js:42
(anonymous) @ typescript.js:43
317.window.__awaiter @ typescript.js:39
(anonymous) @ ExternInterface.ts:653
ExternInterface.gotoScene @ ExternInterface.ts:665
LoginScenHandle.toHall @ LoginSceneHandle.ts:39
onceWrapper @ event-target.js:382
111.EventListeners.invoke @ event-listeners.js:48
112.proto.emit @ event-target.js:443
(anonymous) @ LoginManger.ts:59
(anonymous) @ HandleMsgPack.ts:77
HandleMsgPack.fire @ HandleMsgPack.ts:73
(anonymous) @ HandleMsgPack.ts:11
setInterval (async)
HandleMsgPack.getHandleMsgPack @ HandleMsgPack.ts:10
LoginManger.onLoad @ LoginManger.ts:34
LoginManger @ LoginManger.ts:27
__define @ LoginManger.ts:294
(anonymous) @ LoginManger.ts:296
cc.require @ modular.js:64
__require @ ExternInterface.js:1
__define @ ExternInterface.ts:24
(anonymous) @ ExternInterface.ts:33
run @ modular.js:85
(anonymous) @ boot.js:327
(anonymous) @ CCGame.js:412
(anonymous) @ CCLoader.js:258
(anonymous) @ utils.js:85
setTimeout (async)
callInNextTick @ utils.js:84
(anonymous) @ CCLoader.js:251
139.proto.allComplete @ loading-items.js:527
139.proto.itemComplete @ loading-items.js:715
139.LoadingItems.itemComplete @ loading-items.js:378
142.proto.flowOut @ pipeline.js:318
flow @ pipeline.js:86
(anonymous) @ pipeline.js:63
(anonymous) @ downloader.js:327
loadHandler @ downloader.js:60
load (async)
downloadScript @ downloader.js:68
135.Downloader.handle @ downloader.js:324
135.Downloader._handleLoadQueue @ downloader.js:306
(anonymous) @ downloader.js:326
loadHandler @ downloader.js:60
load (async)
downloadScript @ downloader.js:68
135.Downloader.handle @ downloader.js:324
135.Downloader._handleLoadQueue @ downloader.js:306
(anonymous) @ downloader.js:326
loadHandler @ downloader.js:60
load (async)
downloadScript @ downloader.js:68
135.Downloader.handle @ downloader.js:324
135.Downloader._handleLoadQueue @ downloader.js:306
(anonymous) @ downloader.js:326
loadHandler @ downloader.js:60
load (async)
downloadScript @ downloader.js:68
135.Downloader.handle @ downloader.js:324
flow @ pipeline.js:50
flow @ pipeline.js:83
142.proto.flowIn @ pipeline.js:274
139.proto.append @ loading-items.js:507
130.proto.load @ CCLoader.js:274
prepare @ CCGame.js:409
(anonymous) @ CCGame.js:426
_afterEngineLoaded @ CCBoot.js:107
1.cc.initEngine @ CCBoot.js:139
prepare @ CCGame.js:425
(anonymous) @ CCGame.js:350
_loadConfig @ CCGame.js:595
prepare @ CCGame.js:349
run @ CCGame.js:456
window.onload @ boot.js:326
load (async)
(anonymous) @ boot.js:174
(anonymous) @ boot.js:416
看不出什么原因,你测试的creator版本是多少,可以附上你的切换场景部分的代码吗?可以来个demo最好了。
cc.director.preloadScene(sceneName, function () {
LayerUtil.closeLoadLayer();
cc.director.loadScene(sceneName,function(){
cc.director.getScene().name = sceneName;
});
});
切换场景的代码
找到问题了,是因为在onload内有加载远端图片操作