MatchMaster/.codex_tmp/sprite-load-error-probe.js

47 lines
2.0 KiB
JavaScript

// 仅用于诊断测试包。复制到 build/wechatgame/ 后,在 game.js 中
// __globalAdapter.adaptEngine() 后、require('./ccRequire') 前添加:
// require('./sprite-load-error-probe');
// 本文件不会自动进入构建或修改资源生命周期;异常记录后继续抛出原错误。
(function installSpriteLoadProbe() {
var proto = cc.Sprite.prototype;
var original = proto._applySpriteFrame;
if (original.__spriteLoadProbe) return;
function probe() {
var frame = this._spriteFrame;
try {
return original.apply(this, arguments);
} catch (error) {
try {
var path = [];
for (var node = this.node; node; node = node.parent) {
path.unshift(node.name);
}
var texture = frame && frame.getTexture();
console.error('[SpriteLoadError]', JSON.stringify({
engineVersion: cc.ENGINE_VERSION,
nodePath: path.join('/'),
nodeValid: cc.isValid(this.node, true),
spriteValid: cc.isValid(this, true),
frameName: frame && frame.name,
frameUuid: frame && frame._uuid,
frameFlags: frame && frame._objFlags,
frameValid: cc.isValid(frame, true),
callbackTableNull: !!frame && frame._callbackTable === null,
textureUuid: texture && texture._uuid,
textureValid: cc.isValid(texture, true),
textureLoaded: !!texture && texture.loaded,
message: String(error)
}));
} catch (loggingError) {
console.error('[SpriteLoadError] diagnostic failed', loggingError);
}
throw error;
}
}
probe.__spriteLoadProbe = true;
proto._applySpriteFrame = probe;
console.info('[SpriteLoadProbe] installed; engineVersion=' + cc.ENGINE_VERSION);
})();