Skip to content

Commit

Permalink
Fix LT-22011: Adding slots lead to crash (#239)
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 13, 2024
1 parent d8c3326 commit a41e13c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 42 deletions.
16 changes: 14 additions & 2 deletions Src/Common/Controls/DetailControls/DataTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,11 @@ public void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
// return;
if (m_monitoredProps.Contains(Tuple.Create(hvo, tag)))
{
RefreshList(false);
OnFocusFirstPossibleSlice(null);
// If we call RefreshList now, it causes a crash in the invoker
// because some slice data structures that are being used by the invoker
// get disposed by RefreshList (LT-21980, LT-22011). So we postpone calling
// RefreshList until the work is done.
this.BeginInvoke(new Action(PostponedRefreshList));
}
// Note, in LinguaLinks import we don't have an action handler when we hit this.
else if (m_cache.DomainDataByFlid.GetActionHandler() != null && m_cache.DomainDataByFlid.GetActionHandler().IsUndoOrRedoInProgress)
Expand All @@ -581,6 +584,15 @@ public void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
}
}

private void PostponedRefreshList()
{
if (!IsDisposed)
{
RefreshList(false);
OnFocusFirstPossibleSlice(null);
}
}

/// <summary></summary>
public Mediator Mediator
{
Expand Down
29 changes: 0 additions & 29 deletions Src/Common/Controls/DetailControls/MSAReferenceComboBoxSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ 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 @@ -225,33 +223,6 @@ 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
11 changes: 0 additions & 11 deletions Src/LexText/LexTextControls/MSAPopupTreeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public class MSAPopupTreeManager : PopupTreeManager

#region Events

public event TreeViewEventHandler BeforeChange;
public event TreeViewEventHandler AfterChange;

#endregion Events

/// <summary>
Expand Down Expand Up @@ -422,19 +419,11 @@ 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 a41e13c

Please sign in to comment.