Fixed a large memory leak when reloading the system view.

This commit is contained in:
Leon Styhre 2020-08-15 09:28:47 +02:00
parent d3d57ae69a
commit 7b76aa005f
7 changed files with 17 additions and 9 deletions

View file

@ -35,6 +35,16 @@ SystemView::SystemView(
populate(); populate();
} }
SystemView::~SystemView()
{
// Delete any existing extras.
for (auto entry : mEntries) {
for (auto extra : entry.data.backgroundExtras)
delete extra;
entry.data.backgroundExtras.clear();
}
}
void SystemView::populate() void SystemView::populate()
{ {
mEntries.clear(); mEntries.clear();
@ -110,10 +120,6 @@ void SystemView::populate()
Vector2f denormalized = mCarousel.logoSize * e.data.logo->getOrigin(); Vector2f denormalized = mCarousel.logoSize * e.data.logo->getOrigin();
e.data.logo->setPosition(denormalized.x(), denormalized.y(), 0.0); e.data.logo->setPosition(denormalized.x(), denormalized.y(), 0.0);
// Delete any existing extras.
for (auto extra : e.data.backgroundExtras)
delete extra;
e.data.backgroundExtras.clear();
// Make background extras. // Make background extras.
e.data.backgroundExtras = ThemeData::makeExtras((*it)->getTheme(), "system", mWindow); e.data.backgroundExtras = ThemeData::makeExtras((*it)->getTheme(), "system", mWindow);

View file

@ -52,6 +52,7 @@ class SystemView : public IList<SystemViewData, SystemData*>
{ {
public: public:
SystemView(Window* window); SystemView(Window* window);
~SystemView();
virtual void onShow() override; virtual void onShow() override;
virtual void onHide() override; virtual void onHide() override;

View file

@ -43,6 +43,7 @@ ISimpleGameListView::ISimpleGameListView(
ISimpleGameListView::~ISimpleGameListView() ISimpleGameListView::~ISimpleGameListView()
{ {
// Remove theme extras.
for (auto extra : mThemeExtras) { for (auto extra : mThemeExtras) {
removeChild(extra); removeChild(extra);
delete extra; delete extra;

View file

@ -16,7 +16,7 @@ FT_Library Font::sLibrary = nullptr;
int Font::getSize() const { return mSize; } int Font::getSize() const { return mSize; }
std::map< std::pair<std::string, int>, std::weak_ptr<Font> > Font::sFontMap; std::map<std::pair<std::string, int>, std::weak_ptr<Font>> Font::sFontMap;
Font::FontFace::FontFace(ResourceData&& d, int size) : data(d) Font::FontFace::FontFace(ResourceData&& d, int size) : data(d)
{ {
@ -213,7 +213,7 @@ std::vector<std::string> getFallbackFontPaths()
{ {
std::vector<std::string> fontPaths; std::vector<std::string> fontPaths;
// Standard fonts, let's include them here for error checking purposes even though that's // Standard fonts, let's include them here for exception handling purposes even though that's
// not really the correct location. (The application will crash if they are missing.) // not really the correct location. (The application will crash if they are missing.)
ResourceManager::getInstance()-> ResourceManager::getInstance()->
getResourcePath(":/fonts/opensans_hebrew_condensed_light.ttf"); getResourcePath(":/fonts/opensans_hebrew_condensed_light.ttf");

View file

@ -93,7 +93,7 @@ public:
private: private:
static FT_Library sLibrary; static FT_Library sLibrary;
static std::map< std::pair<std::string, int>, std::weak_ptr<Font> > sFontMap; static std::map<std::pair<std::string, int>, std::weak_ptr<Font>> sFontMap;
Font(int size, const std::string& path); Font(int size, const std::string& path);

View file

@ -66,7 +66,7 @@ public:
std::shared_ptr<TextureData> add(const TextureResource* key, bool tiled); std::shared_ptr<TextureData> add(const TextureResource* key, bool tiled);
// The texturedata being removed may be loading in a different thread. However it will // The texturedata being removed may be loading in a different thread. However it will
// be referenced by a smart point so we only need to remove it from our array and it // be referenced by a smart pointer so we only need to remove it from our array and it
// will be deleted when the other thread has finished with it. // will be deleted when the other thread has finished with it.
void remove(const TextureResource* key); void remove(const TextureResource* key);

View file

@ -137,7 +137,7 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path, b
// Is it an SVG? // Is it an SVG?
if (key.first.substr(key.first.size() - 4, std::string::npos) != ".svg") { if (key.first.substr(key.first.size() - 4, std::string::npos) != ".svg") {
// Probably not. Add it to our map. We don't add SVGs because 2 svgs might be // Probably not. Add it to our map. We don't add SVGs because 2 SVGs might be
// rasterized at different sizes. // rasterized at different sizes.
sTextureMap[key] = std::weak_ptr<TextureResource>(tex); sTextureMap[key] = std::weak_ptr<TextureResource>(tex);
} }