Skip to content

Commit 09b469b

Browse files
Harden BetterLabel against being disposed while changing forms (BL-15424)
1 parent 9de838e commit 09b469b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616

1717
## [Unreleased]
1818

19+
### Fixed
20+
- [SIL.Windows.Forms] Prevent BetterLabel from responding to OnTextChanged when it has been disposed.
21+
1922
### Changed
2023

2124
- [SIL.Windows.Forms] BREAKING CHANGE: Upgraded to L10nSharp v9. Any clients which also use L10nSharp must also upgrade to v9.

SIL.Windows.Forms/Widgets/BetterLabel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ protected override void OnParentChanged(EventArgs e)
134134

135135
protected override void OnTextChanged(EventArgs e)
136136
{
137+
if (IsDisposed)
138+
return; // This has happened in Bloom (BL-15424) and caused a crash.
137139
//this is apparently dangerous to do in the constructor
138140
//Font = new Font(SystemFonts.MessageBoxFont.FontFamily, Font.Size, Font.Style);
139-
if(Font==SystemFonts.DefaultFont)
141+
if (Font==SystemFonts.DefaultFont)
140142
Font = SystemFonts.MessageBoxFont;//sets the default, which can then be customized in the designer
141143

142144
DetermineHeight();
@@ -145,6 +147,8 @@ protected override void OnTextChanged(EventArgs e)
145147

146148
private void DetermineHeight()
147149
{
150+
if (IsDisposed)
151+
return; // This has happened in Bloom (BL-15424) and caused a crash.
148152
using (var g = this.CreateGraphics())
149153
{
150154
// Use this rather than MeasureString, which uses the obsolete GDI+ and can crash on some

0 commit comments

Comments
 (0)