Skip to content

Commit

Permalink
Fix crash during closing
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisyfox committed Sep 9, 2017
1 parent 81cf141 commit 9d1d560
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ACT.FFXIVTranslate/ACT.FFXIVTranslate/TranslateWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public partial class TranslateWindow : Window, PluginComponent

private IntPtr _handle;

private bool _isClosed = false;

private bool _showOverlay = false;
private bool _autoHide = false;
private string _activatedExePath = null;
Expand All @@ -35,6 +37,7 @@ public TranslateWindow()
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_handle = new WindowInteropHelper(this).Handle;
_isClosed = false;
}

public void AttachToAct(FFXIVTranslatePlugin plugin)
Expand Down Expand Up @@ -69,6 +72,8 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
_controller.OverlayAutoHideChanged -= ControllerOnOverlayAutoHideChanged;
_controller.ShowOverlayChanged -= ControllerOnShowOverlayChanged;
_controller.ActivatedProcessPathChanged -= ControllerOnActivatedProcessPathChanged;

_isClosed = true;
}

private void ControllerOnOverlayMoved(bool fromView, int x, int y)
Expand Down Expand Up @@ -116,6 +121,10 @@ private void ControllerOnOverlayContentUpdated(bool fromView, string content)
{
RichTextBoxContent.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
{
if (_isClosed)
{
return;
}
var textRange = new TextRange(RichTextBoxContent.Document.ContentEnd,
RichTextBoxContent.Document.ContentEnd);
textRange.Load(new MemoryStream(Encoding.UTF8.GetBytes(content)), DataFormats.Rtf);
Expand Down Expand Up @@ -227,6 +236,10 @@ private void ApplyVisibility(bool visibility)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
{
if (_isClosed)
{
return;
}
var t = visibility ? Visibility.Visible : Visibility.Hidden;
if (Visibility != t)
{
Expand Down

0 comments on commit 9d1d560

Please sign in to comment.