From 0433d2fe6a120f3b28140d24ae0026c34d7a4e91 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 29 Mar 2022 11:40:58 +0900 Subject: [PATCH] Add safety to realm instance retrieval in `RealmAccess` --- osu.Game/Database/RealmAccess.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 8574002436..8dbb338980 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -13,6 +13,7 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; +using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Development; using osu.Framework.Input.Bindings; @@ -293,7 +294,18 @@ private void cleanupPendingDeletions() /// Compact this realm. /// /// - public bool Compact() => Realm.Compact(getConfiguration()); + public bool Compact() + { + try + { + return Realm.Compact(getConfiguration()); + } + // Catch can be removed along with entity framework. Is specifically to allow a failure message to arrive to the user (see similar catches in EFToRealmMigrator). + catch (AggregateException ae) when (RuntimeInfo.OS == RuntimeInfo.Platform.macOS && ae.Flatten().InnerException is TypeInitializationException) + { + return true; + } + } /// /// Run work on realm with a return value. @@ -542,6 +554,11 @@ private Realm getRealmInstance() return Realm.GetInstance(getConfiguration()); } + // Catch can be removed along with entity framework. Is specifically to allow a failure message to arrive to the user (see similar catches in EFToRealmMigrator). + catch (AggregateException ae) when (RuntimeInfo.OS == RuntimeInfo.Platform.macOS && ae.Flatten().InnerException is TypeInitializationException) + { + return Realm.GetInstance(); + } finally { if (tookSemaphoreLock)