From d2655c082546033490792d6f3e4d1806ba964e8c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 21 Jan 2022 17:27:30 +0900 Subject: [PATCH] Fix `RealmLive` not necessarily being in refreshed state due to potentially using update context --- osu.Game/Database/RealmLive.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/osu.Game/Database/RealmLive.cs b/osu.Game/Database/RealmLive.cs index 05367160f3..75d84d7cf1 100644 --- a/osu.Game/Database/RealmLive.cs +++ b/osu.Game/Database/RealmLive.cs @@ -51,7 +51,21 @@ namespace osu.Game.Database return; } - realmFactory.Run(realm => perform(realm.Find(ID))); + realmFactory.Run(realm => + { + var found = realm.Find(ID); + + if (found == null) + { + // It may be that we access this from the update thread before a refresh has taken place. + // To ensure that behaviour matches what we'd expect (the object *is* available), force + // a refresh to bring in any off-thread changes immediately. + realm.Refresh(); + found = realm.Find(ID); + } + + perform(found); + }); } ///