From 7c9c32c5dc8664b59652c533cf5815db02674430 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sat, 12 Oct 2024 09:27:13 +0200 Subject: [PATCH] Fix crash while translating subtitles - thx claudemartin :) Fix #8901 --- src/ui/Forms/Translate/AutoTranslate.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ui/Forms/Translate/AutoTranslate.cs b/src/ui/Forms/Translate/AutoTranslate.cs index 54bf13302..1fabea940 100644 --- a/src/ui/Forms/Translate/AutoTranslate.cs +++ b/src/ui/Forms/Translate/AutoTranslate.cs @@ -1380,17 +1380,22 @@ namespace Nikse.SubtitleEdit.Forms.Translate private static void SyncListViews(ListView listViewSelected, SubtitleListView listViewOther) { - if (listViewSelected.SelectedItems.Count > 0) + if (listViewSelected == null || + listViewOther == null || + listViewSelected.SelectedItems.Count == 0 || + listViewSelected.TopItem == null) { - var first = listViewSelected.TopItem.Index; - var index = listViewSelected.SelectedItems[0].Index; - if (index < listViewOther.Items.Count) + return; + } + + var first = listViewSelected.TopItem.Index; + var index = listViewSelected.SelectedItems[0].Index; + if (index < listViewOther.Items.Count) + { + listViewOther.SelectIndexAndEnsureVisible(index, false); + if (first >= 0) { - listViewOther.SelectIndexAndEnsureVisible(index, false); - if (first >= 0) - { - listViewOther.TopItem = listViewOther.Items[first]; - } + listViewOther.TopItem = listViewOther.Items[first]; } } }