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);
|
unpackConfig.onProgress && unpackConfig.onProgress(0);
|
||||||
let totalZipNumber = 0, progress = 0;
|
let totalZipNumber = 0, progress = 0;
|
||||||
|
|
||||||
|
// 每次解包前确保 loader 可用
|
||||||
|
if (!this.loader) {
|
||||||
|
this.loader = new ObjectLoader();
|
||||||
|
}
|
||||||
|
|
||||||
await this.initOfflineSource(unpackConfig);
|
await this.initOfflineSource(unpackConfig);
|
||||||
|
|
||||||
if (!this.offlineZipMap && !this.offlineFlatPackages) {
|
if (!this.offlineZipMap && !this.offlineFlatPackages) {
|
||||||
@ -998,8 +1003,7 @@ export class Package {
|
|||||||
that.offlineFlatPackages = null;
|
that.offlineFlatPackages = null;
|
||||||
that.offlineFlatEntryBase = null;
|
that.offlineFlatEntryBase = null;
|
||||||
that.dataComponentMap = null;
|
that.dataComponentMap = null;
|
||||||
// @ts-ignore 清除loader
|
// 不清除 loader,避免连续导入时被上一轮异步收尾误清理
|
||||||
that.loader = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const complete = () => {
|
const complete = () => {
|
||||||
@ -1436,8 +1440,26 @@ export class Package {
|
|||||||
|
|
||||||
const parse = (json) => {
|
const parse = (json) => {
|
||||||
if (check(json.object, json)) {
|
if (check(json.object, json)) {
|
||||||
if (!loader) return;
|
if (!loader) {
|
||||||
loader.parse(json, (group) => {
|
// 生产环境定位: 打印关键上下文和调用栈
|
||||||
|
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[] = [];
|
const bones: Bone[] = [];
|
||||||
group.getObjectsByProperty("type", "Bone", bones);
|
group.getObjectsByProperty("type", "Bone", bones);
|
||||||
if (bones.length > 0) {
|
if (bones.length > 0) {
|
||||||
@ -1469,7 +1491,22 @@ export class Package {
|
|||||||
funcMap.forEach((func, uuid) => {
|
funcMap.forEach((func, uuid) => {
|
||||||
func.call(this, uuid, group, rootGroupUuid);
|
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 {
|
} else {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user