fix(sdk): fix loader lifecycle for consecutive offline pack imports
This commit is contained in:
parent
6720a3e730
commit
83684b4c7b
@ -964,6 +964,11 @@ export class Package {
|
||||
unpackConfig.onProgress && unpackConfig.onProgress(0);
|
||||
let totalZipNumber = 0, progress = 0;
|
||||
|
||||
// 每次解包前确保 loader 可用
|
||||
if (!this.loader) {
|
||||
this.loader = new ObjectLoader();
|
||||
}
|
||||
|
||||
await this.initOfflineSource(unpackConfig);
|
||||
|
||||
if (!this.offlineZipMap && !this.offlineFlatPackages) {
|
||||
@ -998,8 +1003,7 @@ export class Package {
|
||||
that.offlineFlatPackages = null;
|
||||
that.offlineFlatEntryBase = null;
|
||||
that.dataComponentMap = null;
|
||||
// @ts-ignore 清除loader
|
||||
that.loader = undefined;
|
||||
// 不清除 loader,避免连续导入时被上一轮异步收尾误清理
|
||||
}
|
||||
|
||||
const complete = () => {
|
||||
@ -1436,7 +1440,25 @@ export class Package {
|
||||
|
||||
const parse = (json) => {
|
||||
if (check(json.object, json)) {
|
||||
if (!loader) return;
|
||||
if (!loader) {
|
||||
// 生产环境定位: 打印关键上下文和调用栈
|
||||
console.error("[Package.unpackGroup] loader is undefined before parse", {
|
||||
uuid,
|
||||
rootGroupUuid,
|
||||
parent,
|
||||
callFunNum: this.callFunNum?.value,
|
||||
hasJson: Boolean(json),
|
||||
childCount: json?.object?.children?.length,
|
||||
currentLoader: this.loader,
|
||||
capturedLoader: loader,
|
||||
stack: new Error("[Package.unpackGroup] missing loader").stack
|
||||
});
|
||||
|
||||
// 防止早退导致 callFunNum 无法归零,进度卡住
|
||||
this.callFunNum.value--;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
loader.parse(json, (group) => {
|
||||
const bones: Bone[] = [];
|
||||
group.getObjectsByProperty("type", "Bone", bones);
|
||||
@ -1470,6 +1492,21 @@ export class Package {
|
||||
func.call(this, uuid, group, rootGroupUuid);
|
||||
})
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("[Package.unpackGroup] loader.parse threw", {
|
||||
uuid,
|
||||
rootGroupUuid,
|
||||
parent,
|
||||
callFunNum: this.callFunNum?.value,
|
||||
hasJson: Boolean(json),
|
||||
childCount: json?.object?.children?.length,
|
||||
currentLoader: this.loader,
|
||||
capturedLoader: loader,
|
||||
err,
|
||||
stack: err instanceof Error ? err.stack : new Error("[Package.unpackGroup] parse error").stack
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
} else {
|
||||
const timer = setTimeout(() => {
|
||||
clearTimeout(timer);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user