mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 02:42:54 +08:00
Guard against disposal in all context retrievals
This commit is contained in:
parent
8557530cd5
commit
b51fd00ba3
@ -51,7 +51,7 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
context = createContext();
|
context = CreateContext();
|
||||||
Logger.Log($"Opened realm \"{context.Config.DatabasePath}\" at version {context.Config.SchemaVersion}");
|
Logger.Log($"Opened realm \"{context.Config.DatabasePath}\" at version {context.Config.SchemaVersion}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,14 +73,6 @@ namespace osu.Game.Database
|
|||||||
Filename += realm_extension;
|
Filename += realm_extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Realm CreateContext()
|
|
||||||
{
|
|
||||||
if (IsDisposed)
|
|
||||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
|
||||||
|
|
||||||
return createContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compact this realm.
|
/// Compact this realm.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -98,8 +90,11 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Realm createContext()
|
public Realm CreateContext()
|
||||||
{
|
{
|
||||||
|
if (IsDisposed)
|
||||||
|
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
contextCreationLock.Wait();
|
contextCreationLock.Wait();
|
||||||
@ -160,8 +155,11 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
lock (contextLock)
|
||||||
{
|
{
|
||||||
context?.Dispose();
|
context?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
if (!IsDisposed)
|
if (!IsDisposed)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user