From ef1eff72022eb635107f90952cc137da0521e3ce Mon Sep 17 00:00:00 2001 From: Song jh Date: Tue, 4 Aug 2026 00:19:09 +0900 Subject: [PATCH] fix ige snapshot sharing state with the live handler snapshot() returned the player entries by reference, so a snapshot kept changing along with the live handler: receive() decrements item.amount on the very objects the snapshot holds. Restoring one left less cancellation available than it should, so more garbage landed. fromSnapshot() had the mirror problem, inserting the given objects straight into the live map. --- src/engine/multiplayer/ige.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engine/multiplayer/ige.ts b/src/engine/multiplayer/ige.ts index 9cc690c..658df52 100644 --- a/src/engine/multiplayer/ige.ts +++ b/src/engine/multiplayer/ige.ts @@ -1,4 +1,4 @@ -import { polyfills } from "../utils"; +import { deepCopy, polyfills } from "../utils"; export interface GarbageRecord { amount: number; @@ -117,7 +117,7 @@ export class IGEHandler { snapshot(): IGEHandlerSnapshot { return { - players: Object.fromEntries(this.#players.entries()), + players: deepCopy(Object.fromEntries(this.#players.entries())), iid: this.#iid }; } @@ -127,7 +127,7 @@ export class IGEHandler { const entries = Object.entries(snapshot.players); for (let i = 0; i < entries.length; i++) { const [k, v] = entries[i]; - this.#players.set(Number(k), v); + this.#players.set(Number(k), deepCopy(v)); } this.#iid = snapshot.iid; }