From 348d1d0be910ccacf482360150c6b77634af560b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 26 Nov 2021 21:33:11 +0900 Subject: [PATCH] Don't dispose fetched realm instance when using `RealmLive.Value` See https://github.com/realm/realm-dotnet/discussions/2734#discussioncomment-1705038 for reasoning. --- osu.Game/Database/RealmLive.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game/Database/RealmLive.cs b/osu.Game/Database/RealmLive.cs index 45b598ed92..6d5410d1cd 100644 --- a/osu.Game/Database/RealmLive.cs +++ b/osu.Game/Database/RealmLive.cs @@ -100,10 +100,11 @@ public T Value if (originalDataValid) return data; - T retrieved; + if (!isCorrectThread) + throw new InvalidOperationException($"Can't use {nameof(Value)} unless on the same thread the original data was fetched from."); - using (var realm = Realm.GetInstance(data.Realm.Config)) - retrieved = realm.Find(ID); + var realm = Realm.GetInstance(data.Realm.Config); + var retrieved = realm.Find(ID); if (!retrieved.IsValid) throw new InvalidOperationException("Attempted to access value without an open context");