From 1859217c08fb5bdc3ff312042b2bd5bb06c7dfa7 Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Mon, 6 May 2019 11:17:30 +0200 Subject: [PATCH] [PVR] Fix group manager crash when adding a new group. Closes #16079. --- xbmc/pvr/channels/PVRChannelGroup.cpp | 8 ++++---- xbmc/pvr/channels/PVRChannelGroup.h | 10 ++++++---- xbmc/pvr/channels/PVRChannelGroups.cpp | 5 ++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/xbmc/pvr/channels/PVRChannelGroup.cpp b/xbmc/pvr/channels/PVRChannelGroup.cpp index a3ebd15eb90cd..77b83b783a272 100644 --- a/xbmc/pvr/channels/PVRChannelGroup.cpp +++ b/xbmc/pvr/channels/PVRChannelGroup.cpp @@ -34,13 +34,13 @@ using namespace PVR; -CPVRChannelGroup::CPVRChannelGroup(void) +CPVRChannelGroup::CPVRChannelGroup() { OnInit(); } CPVRChannelGroup::CPVRChannelGroup(bool bRadio, - unsigned int iGroupId, + int iGroupId, const std::string& strGroupName, const std::shared_ptr& allChannelsGroup) : m_bRadio(bRadio), @@ -773,11 +773,11 @@ bool CPVRChannelGroup::Persist(void) CSingleLock lock(m_critSection); /* only persist if the group has changes and is fully loaded or never has been saved before */ - if (!HasChanges() || (!m_bLoaded && m_iGroupId != -1)) + if (!HasChanges() || (!m_bLoaded && m_iGroupId != INVALID_GROUP_ID)) return bReturn; // Mark newly created groups as loaded so future updates will also be persisted... - if (m_iGroupId == -1) + if (m_iGroupId == INVALID_GROUP_ID) m_bLoaded = true; if (database) diff --git a/xbmc/pvr/channels/PVRChannelGroup.h b/xbmc/pvr/channels/PVRChannelGroup.h index eca9feb89df26..e0253767f084f 100644 --- a/xbmc/pvr/channels/PVRChannelGroup.h +++ b/xbmc/pvr/channels/PVRChannelGroup.h @@ -59,16 +59,16 @@ namespace PVR friend class CPVRDatabase; public: - CPVRChannelGroup(void); + static const int INVALID_GROUP_ID = -1; /*! * @brief Create a new channel group instance. * @param bRadio True if this group holds radio channels. - * @param iGroupId The database ID of this group. + * @param iGroupId The database ID of this group or INVALID_GROUP_ID if the group was not yet stored in the database. * @param strGroupName The name of this group. * @param allChannelsGroup The channel group containing all TV or radio channels. */ - CPVRChannelGroup(bool bRadio, unsigned int iGroupId, const std::string& strGroupName, const std::shared_ptr& allChannelsGroup); + CPVRChannelGroup(bool bRadio, int iGroupId, const std::string& strGroupName, const std::shared_ptr& allChannelsGroup); /*! * @brief Create a new channel group instance from a channel group provided by an add-on. @@ -433,6 +433,8 @@ namespace PVR bool IsMissingChannelsFromClient(int iClientId) const; protected: + CPVRChannelGroup(); + /*! * @brief Init class */ @@ -500,7 +502,7 @@ namespace PVR bool m_bRadio = false; /*!< true if this container holds radio channels, false if it holds TV channels */ int m_iGroupType = PVR_GROUP_TYPE_DEFAULT; /*!< The type of this group */ - int m_iGroupId = -1; /*!< The ID of this group in the database */ + int m_iGroupId = INVALID_GROUP_ID; /*!< The ID of this group in the database */ std::string m_strGroupName; /*!< The name of this group */ bool m_bLoaded = false; /*!< True if this container is loaded, false otherwise */ bool m_bChanged = false; /*!< true if anything changed in this group that hasn't been persisted, false otherwise */ diff --git a/xbmc/pvr/channels/PVRChannelGroups.cpp b/xbmc/pvr/channels/PVRChannelGroups.cpp index 9218c3852b45a..550f89d924490 100644 --- a/xbmc/pvr/channels/PVRChannelGroups.cpp +++ b/xbmc/pvr/channels/PVRChannelGroups.cpp @@ -500,9 +500,8 @@ bool CPVRChannelGroups::AddGroup(const std::string &strName) if (!group) { // create a new group - group = CPVRChannelGroupPtr(new CPVRChannelGroup()); - group->SetRadio(m_bRadio); - group->SetGroupName(strName); + group.reset(new CPVRChannelGroup(m_bRadio, CPVRChannelGroup::INVALID_GROUP_ID, strName, GetGroupAll())); + m_groups.push_back(group); bPersist = true; }