From 39f67cfcdfedaaf3f341dcfe553bf66c2bb834f1 Mon Sep 17 00:00:00 2001 From: Sophia Hadash Date: Sun, 26 Sep 2021 23:58:23 +0200 Subject: [PATCH] finally properly implemented destructor --- es-app/src/views/gamelist/VideoGameListView.h | 5 +++-- es-core/src/components/BadgesComponent.cpp | 16 ++++++++++++---- es-core/src/components/BadgesComponent.h | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/es-app/src/views/gamelist/VideoGameListView.h b/es-app/src/views/gamelist/VideoGameListView.h index 3516d8477..170a0dbbd 100644 --- a/es-app/src/views/gamelist/VideoGameListView.h +++ b/es-app/src/views/gamelist/VideoGameListView.h @@ -20,8 +20,9 @@ class VideoComponent; class VideoGameListView : public BasicGameListView { public: - VideoGameListView(Window* window, FileData* root); - virtual ~VideoGameListView(); + VideoGameListView(Window *window, FileData *root); + + virtual ~VideoGameListView() noexcept; virtual void onShow() override; virtual void onThemeChanged(const std::shared_ptr& theme) override; diff --git a/es-core/src/components/BadgesComponent.cpp b/es-core/src/components/BadgesComponent.cpp index 1a5b5f341..b0f948215 100644 --- a/es-core/src/components/BadgesComponent.cpp +++ b/es-core/src/components/BadgesComponent.cpp @@ -18,6 +18,7 @@ const std::vector BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_CO SLOT_ALTERNATIVE_EMULATOR}; std::map BadgesComponent::mBadgeIcons = std::map(); std::map BadgesComponent::mImageComponents = std::map(); +std::vector BadgesComponent::mInstances = {}; BadgesComponent::BadgesComponent(Window *window) : FlexboxComponent(window) { @@ -48,12 +49,19 @@ BadgesComponent::BadgesComponent(Window *window) mImageAltEmu.setImage(mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR], false, true); mImageComponents.insert({SLOT_ALTERNATIVE_EMULATOR, mImageAltEmu}); } + + mInstances.push_back(this); } -BadgesComponent::~BadgesComponent() { - mChildren.clear(); - mBadgeIcons.clear(); - mImageComponents.clear(); +BadgesComponent::~BadgesComponent() noexcept { + for (GuiComponent *c: mChildren) + c->clearChildren(); + clearChildren(); + mInstances.erase(std::remove(mInstances.begin(), mInstances.end(), this), mInstances.end()); + if (mInstances.empty()) { + mBadgeIcons.clear(); + mImageComponents.clear(); + } } diff --git a/es-core/src/components/BadgesComponent.h b/es-core/src/components/BadgesComponent.h index 7da63e447..4a54fa323 100644 --- a/es-core/src/components/BadgesComponent.h +++ b/es-core/src/components/BadgesComponent.h @@ -28,7 +28,6 @@ class BadgesComponent : public FlexboxComponent { public: BadgesComponent(Window *window); - ~BadgesComponent() noexcept; std::string getValue() const override; @@ -46,6 +45,7 @@ private: static const std::vector mSlots; static std::map mBadgeIcons; static std::map mImageComponents; + static std::vector mInstances; }; #endif // ES_APP_COMPONENTS_BADGES_COMPONENT_H