From 4ae5c397fd577f8ce00253ba7afc42899156378b Mon Sep 17 00:00:00 2001 From: Mute Date: Sat, 8 Aug 2026 10:55:30 +0000 Subject: [PATCH] Fix crash on startup: call OnLimitChanged after _chkScale is initialized The manual OnLimitChanged(null, EventArgs.Empty) call in the constructor was placed before _chkScale was created, causing a NullReferenceException because the handler reads _chkScale.Checked. Moved the call to after both _limitBar and _chkScale are created and wired. --- MainForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MainForm.cs b/MainForm.cs index 24123de..e084547 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -182,7 +182,6 @@ public class MainForm : Form Value = 30 }; _limitBar.ValueChanged += OnLimitChanged; - OnLimitChanged(null, EventArgs.Empty); _chkScale = new CheckBox { Text = "Scale", @@ -191,6 +190,7 @@ public class MainForm : Form Checked = false }; _chkScale.CheckedChanged += OnLimitChanged; + OnLimitChanged(null, EventArgs.Empty); Controls.AddRange(new Control[] { _lblBle, _lblWs, _lblStrength, _lblDeviceName, _txtDeviceName, _btnConnect, _btnTest, _btnMusic, _btnStop, _lblTrack, _lblGaugeA, _gaugeA, _lblGaugeB, _gaugeB, _lblLimit, _limitBar, _chkScale });