Commit cf3aaf64 authored by nanahira's avatar nanahira

add more safety

parent 70148f4b
...@@ -446,14 +446,24 @@ export class OcgcoreWorker { ...@@ -446,14 +446,24 @@ export class OcgcoreWorker {
@WorkerMethod() @WorkerMethod()
@WorkerFinalize() @WorkerFinalize()
async dispose() { async dispose() {
// Dump registry and send to master thread via masterFinalize // masterFinalize must always run; fallback to {} when dump fails.
let registryData: Record<string, string> = {};
if (this.duel && !this.duel.ended) { if (this.duel && !this.duel.ended) {
const registryDump = this.duel.dumpRegistry(); try {
await this.masterFinalize(registryDump.dict); const registryDump = this.duel.dumpRegistry();
registryData = registryDump.dict;
} catch (error) {
console.warn('Failed to dump registry in OcgcoreWorker.dispose', error);
}
} }
await this.masterFinalize(registryData);
if (this.duel && !this.duel.ended) { if (this.duel && !this.duel.ended) {
this.duel.endDuel(); try {
this.duel.endDuel();
} catch (e) {
console.warn('Failed to end duel in OcgcoreWorker.dispose', e);
}
} }
this.ocgcore.finalize(); this.ocgcore.finalize();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment