From 7e1e3adf8d35e38a02386ee1045ff49d2d4b558c Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Wed, 29 Jan 2025 16:16:41 +0100 Subject: [PATCH] Add a check to avoid out-of-bounds index error in ContentView.swift --- Linphone/UI/Main/ContentView.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index 9faedf396..a16502b30 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -340,13 +340,22 @@ struct ContentView: View { openMenu() } .onAppear { - imagePath = CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex!].getImagePath() + if let accountModelIndex = accountProfileViewModel.accountModelIndex, + accountModelIndex < CoreContext.shared.accounts.count { + imagePath = CoreContext.shared.accounts[accountModelIndex].getImagePath() + } } - .onChange(of: CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex!].usernaneAvatar) { _ in - imagePath = CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex!].getImagePath() + .onChange(of: CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex ?? 0].usernaneAvatar) { _ in + if let accountModelIndex = accountProfileViewModel.accountModelIndex, + accountModelIndex < CoreContext.shared.accounts.count { + imagePath = CoreContext.shared.accounts[accountModelIndex].getImagePath() + } } .onReceive(imageChanged) { _ in - imagePath = CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex!].getImagePath() + if let accountModelIndex = accountProfileViewModel.accountModelIndex, + accountModelIndex < CoreContext.shared.accounts.count { + imagePath = CoreContext.shared.accounts[accountModelIndex].getImagePath() + } } }