From 2b189f9d19602cd3ee633f3565ec405719150865 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 14 Nov 2020 17:18:00 +0100 Subject: [PATCH] Fixed an issue where the game image would sometimes not refresh after scraping. --- es-app/src/guis/GuiMetaDataEd.cpp | 18 ++++++++---------- es-core/src/resources/TextureResource.cpp | 12 ++++++++++++ es-core/src/resources/TextureResource.h | 5 +++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index cad04fbd1..744429199 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -464,18 +464,16 @@ void GuiMetaDataEd::close() std::function closeFunc; closeFunc = [this] { - ViewController::get()->onPauseVideo(); - delete this; - }; - - std::function closeFuncReload; - closeFuncReload = [this] { - // Always reload the gamelist if media files were updated, even if the user - // selected to not save any metadata changes. if (mMediaFilesUpdated) { + // Always reload the gamelist if media files were updated, even if the user + // chose to not save any metadata changes. Also manually unload the game image + // and marquee, as otherwise they would not get updated until the user scrolls up + // and down the gamelist. + TextureResource::manualUnload(mScraperParams.game->getImagePath(), false); + TextureResource::manualUnload(mScraperParams.game->getMarqueePath(), false); ViewController::get()->reloadGameListView(mScraperParams.system); - ViewController::get()->onPauseVideo(); } + ViewController::get()->onPauseVideo(); delete this; }; @@ -484,7 +482,7 @@ void GuiMetaDataEd::close() mWindow->pushGui(new GuiMsgBox(mWindow, getHelpStyle(), "SAVE CHANGES?", "YES", [this, closeFunc] { save(); closeFunc(); }, - "NO", closeFuncReload + "NO", closeFunc )); } else { diff --git a/es-core/src/resources/TextureResource.cpp b/es-core/src/resources/TextureResource.cpp index 4ed47de47..cd10535e3 100644 --- a/es-core/src/resources/TextureResource.cpp +++ b/es-core/src/resources/TextureResource.cpp @@ -87,6 +87,18 @@ void TextureResource::initFromMemory(const char* data, size_t length) mSourceSize = Vector2f(mTextureData->sourceWidth(), mTextureData->sourceHeight()); } +void TextureResource::manualUnload(std::string path, bool tile) +{ + const std::string canonicalPath = Utils::FileSystem::getCanonicalPath(path); + + TextureKeyType key(canonicalPath, tile); + auto foundTexture = sTextureMap.find(key); + + if (foundTexture != sTextureMap.cend()) { + sTextureMap.erase(foundTexture); + } +} + const Vector2i TextureResource::getSize() const { return mSize; diff --git a/es-core/src/resources/TextureResource.h b/es-core/src/resources/TextureResource.h index dc1ad4ffa..e652cdb3d 100644 --- a/es-core/src/resources/TextureResource.h +++ b/es-core/src/resources/TextureResource.h @@ -9,8 +9,8 @@ #ifndef ES_CORE_RESOURCES_TEXTURE_RESOURCE_H #define ES_CORE_RESOURCES_TEXTURE_RESOURCE_H -#include "math/Vector2i.h" #include "math/Vector2f.h" +#include "math/Vector2i.h" #include "resources/ResourceManager.h" #include "resources/TextureDataManager.h" @@ -28,6 +28,7 @@ public: bool forceLoad = false, bool dynamic = true); void initFromPixels(const unsigned char* dataRGBA, size_t width, size_t height); virtual void initFromMemory(const char* data, size_t length); + static void manualUnload(std::string path, bool tile); // For scalable source images in textures we want to set the resolution to rasterize at. void rasterizeAt(size_t width, size_t height); @@ -65,7 +66,7 @@ private: typedef std::pair TextureKeyType; // Map of textures, used to prevent duplicate textures. - static std::map< TextureKeyType, std::weak_ptr > sTextureMap; + static std::map> sTextureMap; // Set of all textures, used for memory management. static std::set sAllTextures; };