Skip to content

Commit

Permalink
Viewer: Fixed bug where game over message is displayed more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
jonthysell committed Aug 23, 2021
1 parent 3ceb59e commit 253a635
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## next ##

* Engine: Fixed bug where pondering starts after a game is over, causing an error
* Viewer: Fixed bug where game over message is displayed more than once
* Viewer: Update Avalonia to 0.10.7

## v0.11.3 ##
Expand Down
19 changes: 15 additions & 4 deletions src/Mzinga.Viewer/MessageHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ private static async Task ShowExceptionAsync(ExceptionMessage message)
{
try
{
Trace.TraceInformation($"ShowExceptionAsync: { message.ExceptionVM.Exception }");

InformationWindow window = new InformationWindow
{
VM = message.ExceptionVM,
Expand All @@ -73,16 +75,25 @@ private static async Task ShowExceptionAsync(ExceptionMessage message)
}
}

// Code dispatched to Avalonia's UI thread sometimes runs multiple times, which causes us to display multiple game over messages
private static volatile InformationWindow _currentInformationWindow = null;

private static async Task ShowInformationAsync(InformationMessage message)
{
try
{
InformationWindow window = new InformationWindow
Trace.TraceInformation($"ShowInformationAsync: { message.InformationVM.Message }");

if (_currentInformationWindow is null)
{
VM = message.InformationVM,
};
_currentInformationWindow = new InformationWindow
{
VM = message.InformationVM,
};

await window.ShowDialog(MainWindow);
await _currentInformationWindow.ShowDialog(MainWindow);
_currentInformationWindow = null;
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 253a635

Please sign in to comment.