From 6c0cf6832e351f8800f3371a7f64f0a101625623 Mon Sep 17 00:00:00 2001 From: vsariola <5684185+vsariola@users.noreply.github.com> Date: Sat, 6 Feb 2021 19:15:06 +0200 Subject: [PATCH] fix(tracker): clamp CurrentUnit to valid values when instrument changes --- tracker/instruments.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tracker/instruments.go b/tracker/instruments.go index c8e5885..b4f0fa5 100644 --- a/tracker/instruments.go +++ b/tracker/instruments.go @@ -112,6 +112,9 @@ func (t *Tracker) layoutInstrumentNames(gtx C) D { dims := instrumentList.Layout(gtx) if t.CurrentInstrument != t.InstrumentDragList.SelectedItem { t.CurrentInstrument = t.InstrumentDragList.SelectedItem + if l := len(t.song.Patch.Instruments[t.CurrentInstrument].Units); t.CurrentUnit >= l { + t.CurrentUnit = l - 1 + } op.InvalidateOp{}.Add(gtx.Ops) } return dims