Fix skin editor freezing game if opened during active gameplay

This commit is contained in:
Bartłomiej Dach 2023-10-27 14:34:30 +02:00
parent b5cb538004
commit 5ad962070c
No known key found for this signature in database
3 changed files with 13 additions and 4 deletions

View File

@ -21,5 +21,11 @@ public struct ImportParameters
/// Whether this import should use hard links rather than file copy operations if available.
/// </summary>
public bool PreferHardLinks { get; set; }
/// <summary>
/// If set to <see langword="true"/>, this import will not respect <see cref="RealmArchiveModelImporter{TModel}.PauseImports"/>.
/// This is useful for cases where an import <em>must</em> complete even if gameplay is in progress.
/// </summary>
public bool ImportImmediately { get; set; }
}
}

View File

@ -261,7 +261,7 @@ await Task.WhenAll(tasks.Select(async task =>
/// <param name="cancellationToken">An optional cancellation token.</param>
public virtual Live<TModel>? ImportModel(TModel item, ArchiveReader? archive = null, ImportParameters parameters = default, CancellationToken cancellationToken = default) => Realm.Run(realm =>
{
pauseIfNecessary(cancellationToken);
pauseIfNecessary(parameters, cancellationToken);
TModel? existing;
@ -560,9 +560,9 @@ protected virtual void UndeleteForReuse(TModel existing)
/// <returns>Whether to perform deletion.</returns>
protected virtual bool ShouldDeleteArchive(string path) => false;
private void pauseIfNecessary(CancellationToken cancellationToken)
private void pauseIfNecessary(ImportParameters importParameters, CancellationToken cancellationToken)
{
if (!PauseImports)
if (!PauseImports || importParameters.ImportImmediately)
return;
Logger.Log($@"{GetType().Name} is being paused.");

View File

@ -182,7 +182,10 @@ public bool EnsureMutableSkin()
Name = NamingUtils.GetNextBestName(existingSkinNames, $@"{s.Name} (modified)")
};
var result = skinImporter.ImportModel(skinInfo);
var result = skinImporter.ImportModel(skinInfo, parameters: new ImportParameters
{
ImportImmediately = true // to avoid possible deadlocks when editing skin during gameplay.
});
if (result != null)
{