Skip to content

Commit

Permalink
Fix LT-21980: Crash changing or modifying grammatical info (#235)
Browse files Browse the repository at this point in the history
Co-authored-by: Jake Oliver <[email protected]>
  • Loading branch information
jtmaxwell3 and JakeOliver28 authored Dec 12, 2024
1 parent d02b42a commit eb4a00b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Bin/_setLatestBuildConfig.bat
Bin/_setroot.bat
Lib/debug/DebugProcs.lib
Lib/debug/Generic.lib
Lib/debug/System.ValueTuple.dll
Lib/debug/unit++.*
Lib/release/DebugProcs.lib
Lib/release/Generic.lib
Expand Down
32 changes: 32 additions & 0 deletions Src/Common/Controls/DetailControls/MSAReferenceComboBoxSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class MSAReferenceComboBoxSlice : FieldSlice, IVwNotifyChange

//private bool m_processSelectionEvent = true;
private bool m_handlingMessage = false;
private bool m_forceRefresh = false;

/// ------------------------------------------------------------------------------------
/// <summary>
Expand Down Expand Up @@ -98,6 +99,8 @@ public override Mediator Mediator
m_MSAPopupTreeManager = new MSAPopupTreeManager(m_tree, m_cache, list,
m_tree.WritingSystemCode, true, m_mediator, m_propertyTable,
m_propertyTable.GetValue<Form>("window"));
m_MSAPopupTreeManager.BeforeChange += m_MSAPopupTreeManager_BeforeChange;
m_MSAPopupTreeManager.AfterChange += m_MSAPopupTreeManager_AfterChange;
m_MSAPopupTreeManager.AfterSelect += m_MSAPopupTreeManager_AfterSelect;
m_MSAPopupTreeManager.Sense = m_obj as ILexSense;
m_MSAPopupTreeManager.PersistenceProvider = m_persistProvider;
Expand Down Expand Up @@ -222,6 +225,33 @@ protected override void UpdateDisplayFromDatabase()
// What do we need to do here, if anything?
}

public void m_MSAPopupTreeManager_BeforeChange(object sender, TreeViewEventArgs e)
{
if (!ContainingDataTree.DoNotRefresh)
{
// Postpone refreshing the screen until m_MSAPopupTreeManager_AfterChange (LT-21980).
ContainingDataTree.DoNotRefresh = true;
m_forceRefresh = true;
}
}

public void m_MSAPopupTreeManager_AfterChange(object sender, TreeViewEventArgs e)
{
if (m_forceRefresh)
{
m_forceRefresh = false;
// We can't call RefreshDataTree directly,
// since that will cause Windows to crash accessing a disposed object.
// So, we queue it on the UI thread instead.
this.BeginInvoke(new Action(RefreshDataTree));
}
}

public void RefreshDataTree()
{
ContainingDataTree.DoNotRefresh = false;
}

private void m_MSAPopupTreeManager_AfterSelect(object sender, TreeViewEventArgs e)
{
// unless we get a mouse click or simulated mouse click (e.g. by ENTER or TAB),
Expand Down Expand Up @@ -286,7 +316,9 @@ private void m_MSAPopupTreeManager_AfterSelect(object sender, TreeViewEventArgs
// We still can't refresh the data at this point without causing a crash due to
// a pending Windows message. See LT-9713 and LT-9714.
if (ContainingDataTree.DoNotRefresh != fOldDoNotRefresh)
{
Mediator.BroadcastMessage("DelayedRefreshList", fOldDoNotRefresh);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions Src/LexText/LexTextControls/MSAPopupTreeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class MSAPopupTreeManager : PopupTreeManager

#region Events

public event TreeViewEventHandler BeforeChange;
public event TreeViewEventHandler AfterChange;

#endregion Events

/// <summary>
Expand Down Expand Up @@ -419,11 +422,19 @@ private bool EditExistingMsa()
m_sense.MorphoSyntaxAnalysisRA.Hvo, true, m_sEditGramFunc);
if (dlg.ShowDialog(ParentForm) == DialogResult.OK)
{
if (BeforeChange != null)
{
BeforeChange(this, null);
}
Cache.DomainDataByFlid.BeginUndoTask(String.Format(LexTextControls.ksUndoSetX, FieldName),
String.Format(LexTextControls.ksRedoSetX, FieldName));
m_sense.SandboxMSA = dlg.SandboxMSA;
Cache.DomainDataByFlid.EndUndoTask();
LoadPopupTree(m_sense.MorphoSyntaxAnalysisRA.Hvo);
if (AfterChange != null)
{
AfterChange(this, null);
}
return true;
}
}
Expand Down

0 comments on commit eb4a00b

Please sign in to comment.