Fix potentially cyclic subscription registration if a subscription's delegate accesses Context

This commit is contained in:
Dean Herbert 2022-01-21 20:45:10 +09:00
parent 1f157d729d
commit 3b11235d3c

View File

@ -88,6 +88,8 @@ namespace osu.Game.Database
registerSubscription(action); registerSubscription(action);
} }
Debug.Assert(context != null);
// creating a context will ensure our schema is up-to-date and migrated. // creating a context will ensure our schema is up-to-date and migrated.
return context; return context;
} }
@ -261,10 +263,13 @@ namespace osu.Game.Database
{ {
Debug.Assert(ThreadSafety.IsUpdateThread); Debug.Assert(ThreadSafety.IsUpdateThread);
// Get context outside of flag update to ensure beyond doubt this can't be cyclic.
var realm = Context;
lock (contextLock) lock (contextLock)
{ {
current_thread_subscriptions_allowed.Value = true; current_thread_subscriptions_allowed.Value = true;
subscriptionActions[action] = action(Context); subscriptionActions[action] = action(realm);
current_thread_subscriptions_allowed.Value = false; current_thread_subscriptions_allowed.Value = false;
} }
} }