From 43ceb82b4eac7d89a41411b0b40014da1d0469b7 Mon Sep 17 00:00:00 2001 From: enen92 <92enen@gmail.com> Date: Fri, 22 Mar 2024 16:05:08 +0000 Subject: stacks: make InitializeStackStartPartAndOffset return optional and handle errors --- xbmc/application/Application.cpp | 10 ++++++++-- xbmc/application/ApplicationStackHelper.cpp | 4 ++-- xbmc/application/ApplicationStackHelper.h | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/xbmc/application/Application.cpp b/xbmc/application/Application.cpp index 3309927de0..e1db281f08 100644 --- a/xbmc/application/Application.cpp +++ b/xbmc/application/Application.cpp @@ -2334,10 +2334,16 @@ bool CApplication::PlayStack(CFileItem& item, bool bRestart) if (!stackHelper->InitializeStack(item)) return false; - int startoffset = stackHelper->InitializeStackStartPartAndOffset(item); + std::optional startoffset = stackHelper->InitializeStackStartPartAndOffset(item); + if (!startoffset) + { + CLog::LogF(LOGERROR, "Failed to obtain start offset for stack {}. Aborting playback.", + item.GetDynPath()); + return false; + } CFileItem selectedStackPart = stackHelper->GetCurrentStackPartFileItem(); - selectedStackPart.SetStartOffset(startoffset); + selectedStackPart.SetStartOffset(startoffset.value()); if (item.HasProperty("savedplayerstate")) { diff --git a/xbmc/application/ApplicationStackHelper.cpp b/xbmc/application/ApplicationStackHelper.cpp index f8070c0d1e..e2c303a0e1 100644 --- a/xbmc/application/ApplicationStackHelper.cpp +++ b/xbmc/application/ApplicationStackHelper.cpp @@ -80,7 +80,7 @@ bool CApplicationStackHelper::InitializeStack(const CFileItem & item) return true; } -int CApplicationStackHelper::InitializeStackStartPartAndOffset(const CFileItem& item) +std::optional CApplicationStackHelper::InitializeStackStartPartAndOffset(const CFileItem& item) { CVideoDatabase dbs; int64_t startoffset = 0; @@ -162,7 +162,7 @@ int CApplicationStackHelper::InitializeStackStartPartAndOffset(const CFileItem& if (!CDVDFileInfo::GetFileDuration(GetStackPartFileItem(i).GetPath(), duration)) { m_currentStack->Clear(); - return false; + return std::nullopt; } totalTimeMs += duration; // set end time in every part diff --git a/xbmc/application/ApplicationStackHelper.h b/xbmc/application/ApplicationStackHelper.h index 6af0044372..4cdbc39e42 100644 --- a/xbmc/application/ApplicationStackHelper.h +++ b/xbmc/application/ApplicationStackHelper.h @@ -13,6 +13,7 @@ #include #include +#include #include class CFileItem; @@ -36,8 +37,9 @@ public: /*! \brief Initialize stack times for each part, start & end, total time, and current part number if resume offset is specified. \param item the FileItem object that is the stack + \returns the part offset if available, nullopt in case of errors */ - int InitializeStackStartPartAndOffset(const CFileItem& item); + std::optional InitializeStackStartPartAndOffset(const CFileItem& item); /*! \brief returns the current part number -- cgit v1.2.3