Fix #729: add bounds checking to LyricsViewer
This commit is contained in:
@@ -95,7 +95,8 @@ func (l *LyricsViewer) UpdatePlayPos(timeSecs float64) {
|
|||||||
}
|
}
|
||||||
l.lastPlayPos = timeSecs
|
l.lastPlayPos = timeSecs
|
||||||
// advance if needed
|
// advance if needed
|
||||||
if l.lyrics.Lines[l.nextLyricLine].Start <= timeSecs {
|
if l.nextLyricLine >= 0 && l.nextLyricLine < len(l.lyrics.Lines) &&
|
||||||
|
l.lyrics.Lines[l.nextLyricLine].Start <= timeSecs {
|
||||||
l.viewer.NextLine()
|
l.viewer.NextLine()
|
||||||
if l.nextLyricLine < len(l.lyrics.Lines)-1 {
|
if l.nextLyricLine < len(l.lyrics.Lines)-1 {
|
||||||
l.nextLyricLine++
|
l.nextLyricLine++
|
||||||
@@ -125,8 +126,10 @@ func (l *LyricsViewer) OnSeeked(timeSecs float64) {
|
|||||||
} else {
|
} else {
|
||||||
l.nextLyricLine = nextLine
|
l.nextLyricLine = nextLine
|
||||||
}
|
}
|
||||||
|
if nextLine >= 0 && nextLine <= len(l.lyrics.Lines) {
|
||||||
l.viewer.SetCurrentLine(nextLine /*one-indexed*/)
|
l.viewer.SetCurrentLine(nextLine /*one-indexed*/)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (l *LyricsViewer) CreateRenderer() fyne.WidgetRenderer {
|
func (l *LyricsViewer) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return widget.NewSimpleRenderer(l.container)
|
return widget.NewSimpleRenderer(l.container)
|
||||||
|
|||||||
Reference in New Issue
Block a user