Skip to content

Commit

Permalink
Skip retrieving sound control rect before refreshing view
Browse files Browse the repository at this point in the history
* Fixes LT-18994

Change-Id: I8844c81ade215577cea33287c62c59cc6a9ee29c
  • Loading branch information
RaymondLuong3 committed Jul 12, 2018
1 parent 18ed4c7 commit a772b66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 10 additions & 2 deletions Src/Common/Controls/Widgets/InnerLabeledMultiStringView.cs
@@ -1,4 +1,4 @@
// Copyright (c) 2010-2017 SIL International
// Copyright (c) 2010-2018 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand Down Expand Up @@ -127,11 +127,19 @@ public void Reuse(int hvo, int flid, int wsMagic, int wsOptional, bool forceIncl
/// <summary>
/// Return the sound control rectangle.
/// </summary>
internal void GetSoundControlRectangle(IVwSelection sel, out Rectangle selRect)
internal bool GetSoundControlRectangle(IVwSelection sel, out Rectangle selRect)
{
// Trying to get the Rectangle for the sound control can cause a crash (LT-18994) if a refresh is pending
// to reconstruct the RootBox. Just return false for now and try again when the refresh is successful.
if (m_fRefreshPending)
{
selRect = new Rectangle(); // Just a dummy
return false;
}
bool fEndBeforeAnchor;
using (new HoldGraphics(this))
SelectionRectangle(sel, out selRect, out fEndBeforeAnchor);
return true;
}

/// <summary>
Expand Down
10 changes: 7 additions & 3 deletions Src/Common/Controls/Widgets/LabeledMultiStringView.cs
@@ -1,4 +1,4 @@
// Copyright (c) 2015 SIL International
// Copyright (c) 2015-2018 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand Down Expand Up @@ -107,9 +107,11 @@ public string TextStyle
/// </summary>
public bool RefreshDisplay()
{
SuspendLayout();
DisposeSoundControls(); // before we do the base refresh, which will layout, and possibly miss a deleted WS.
var ret = m_innerView.RefreshDisplay();
SetupSoundControls();
ResumeLayout();
return ret;
}

Expand Down Expand Up @@ -253,6 +255,8 @@ protected override void OnLayout(LayoutEventArgs levent)
base.OnLayout(levent);
if (m_innerView.VC == null || m_innerView.RootBox == null) // We can come in with no rootb from a dispose call.
return;
if (Visible)
m_innerView.RefreshDisplay();
int dpiX;
using (var graphics = CreateGraphics())
{
Expand All @@ -278,8 +282,8 @@ protected override void OnLayout(LayoutEventArgs levent)
// Leave control.Top zero and hope layout gets called again when we can make
// the selection successfully.
Rectangle selRect;
m_innerView.GetSoundControlRectangle(sel, out selRect);
control.Top = selRect.Top;
if (m_innerView.GetSoundControlRectangle(sel, out selRect))
control.Top = selRect.Top;
}
// Don't crash trying to bring to front if control is not a child control on Linux (FWNX-1348).
// If control.Parent is null, don't crash, and bring to front anyway on Windows (LT-15148).
Expand Down

0 comments on commit a772b66

Please sign in to comment.