Skip to content

Commit

Permalink
Merge pull request #1494 from VladiStep/randomSavingCrashFix
Browse files Browse the repository at this point in the history
A fix of the random saving crash.
  • Loading branch information
colinator27 authored Oct 31, 2023
2 parents 7b876ad + a296c59 commit e308ae8
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2213,14 +2213,12 @@ private async void MenuItem_RunOtherScript_Click(object sender, RoutedEventArgs
}
}

// Apparently, one null check is not enough for `scriptDialog`
public void UpdateProgressBar(string message, string status, double progressValue, double maxValue)
{
if (scriptDialog != null)
{
scriptDialog.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => {
scriptDialog.Update(message, status, progressValue, maxValue);
}));
}
scriptDialog?.Dispatcher.Invoke(DispatcherPriority.Normal, () => {
scriptDialog?.Update(message, status, progressValue, maxValue);
});
}

public void SetProgressBar(string message, string status, double progressValue, double maxValue)
Expand All @@ -2236,33 +2234,28 @@ public void SetProgressBar(string message, string status, double progressValue,
public void SetProgressBar()
{
if (scriptDialog != null && !scriptDialog.IsVisible)
scriptDialog.Dispatcher.Invoke(scriptDialog.Show);
scriptDialog.Dispatcher.Invoke(() => {
scriptDialog?.Show();
});
}

public void UpdateProgressValue(double progressValue)
{
if (scriptDialog != null)
{
scriptDialog.Dispatcher.Invoke(DispatcherPriority.Normal, (Action) (() => {
scriptDialog.ReportProgress(progressValue);
}));
}
scriptDialog?.Dispatcher.Invoke(DispatcherPriority.Normal, () => {
scriptDialog?.ReportProgress(progressValue);
});
}

public void UpdateProgressStatus(string status)
{
if (scriptDialog != null)
{
scriptDialog.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => {
scriptDialog.ReportProgress(status);
}));
}
scriptDialog?.Dispatcher.Invoke(DispatcherPriority.Normal, () => {
scriptDialog?.ReportProgress(status);
});
}

public void HideProgressBar()
{
if (scriptDialog != null)
scriptDialog.TryHide();
scriptDialog?.TryHide();
}

public void AddProgress(int amount)
Expand Down Expand Up @@ -2414,14 +2407,18 @@ public async Task StopProgressBarUpdater() //async because "Wait()" blocks UI th

if (await Task.Run(() => !updater.Wait(2000))) //if ProgressUpdater isn't responding
ScriptError("Stopping the progress bar updater task is failed.\nIt's highly recommended to restart the application.",
"Script error", false);
"Script error", false);
else
{
cts.Dispose();
cts = null;
}

updater.Dispose();
if (!updater.IsCompleted)
ScriptError("Stopping the progress bar updater task is failed.\nIt's highly recommended to restart the application.",
"Script error", false);
else
updater.Dispose();
}

public void OpenCodeFile(string name, CodeEditorMode editorDecompile, bool inNewTab = false)
Expand Down

0 comments on commit e308ae8

Please sign in to comment.