Fix attempt to revive update thread realm context from non-update thread

This commit is contained in:
Dean Herbert 2022-01-24 18:36:16 +09:00
parent b0919722ac
commit 9afa034296

View File

@ -594,7 +594,7 @@ namespace osu.Game.Database
if (isDisposed)
throw new ObjectDisposedException(nameof(RealmContextFactory));
SynchronizationContext syncContext;
SynchronizationContext? syncContext = null;
try
{
@ -602,10 +602,20 @@ namespace osu.Game.Database
lock (contextLock)
{
if (!ThreadSafety.IsUpdateThread && context != null)
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
if (context == null)
{
// null context means the update thread has not yet retrieved its context.
// we don't need to worry about reviving the update context in this case, so don't bother with the SynchronizationContext.
Debug.Assert(!ThreadSafety.IsUpdateThread);
}
else
{
if (!ThreadSafety.IsUpdateThread)
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
syncContext = SynchronizationContext.Current;
}
syncContext = SynchronizationContext.Current;
unregisterAllSubscriptions();
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);