From 624f697beeaae6712edbe68f52ca859ae499c2a1 Mon Sep 17 00:00:00 2001 From: Zihao Xu Date: Wed, 7 Jan 2026 23:30:26 -0800 Subject: [PATCH] fix: pause game during save load to prevent stale events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The game loop could generate events with the old world's timestamp while loading a save, causing 100年1月 events to appear after loading a 106年 save. Now we pause the game before loading and keep it paused after, giving the frontend time to refresh state. --- src/server/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/server/main.py b/src/server/main.py index 7482da4..85a19cc 100644 --- a/src/server/main.py +++ b/src/server/main.py @@ -1307,6 +1307,9 @@ def api_load_game(req: LoadGameRequest): if not target_path.exists(): raise HTTPException(status_code=404, detail="File not found") + # 暂停游戏,防止 game_loop 在加载过程中使用旧 world 生成事件。 + game_instance["is_paused"] = True + # 关闭旧 World 的 EventManager,释放 SQLite 连接。 old_world = game_instance.get("world") if old_world and hasattr(old_world, "event_manager"): @@ -1323,6 +1326,9 @@ def api_load_game(req: LoadGameRequest): game_instance["sim"] = new_sim game_instance["current_save_path"] = target_path + # 加载完成后保持暂停状态,让用户决定何时恢复。 + # 这也给前端时间来刷新状态。 + return {"status": "ok", "message": "Game loaded"} except Exception as e: import traceback