From d8d021060e181feaef6ffb932b0afcfe5223f12c Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 16 Nov 2023 12:58:51 -0800 Subject: [PATCH] handle case where storages are created after snapshot --- src/Snapshot.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Snapshot.cs b/src/Snapshot.cs index 6d124cb..10a080d 100644 --- a/src/Snapshot.cs +++ b/src/Snapshot.cs @@ -43,6 +43,20 @@ public class Snapshot } } + // clear all component storages in case any were created after snapshot + // FIXME: this can be eliminated via component discovery + foreach (var (typeId, componentStorage) in world.ComponentIndex) + { + componentStorage.Clear(); + } + + // clear all relation storages in case any were created after snapshot + // FIXME: this can be eliminated via component discovery + foreach (var (typeId, relationStorage) in world.RelationIndex) + { + relationStorage.Clear(); + } + // restore components foreach (var (typeId, componentSnapshot) in ComponentSnapshots) {