From 47c40d51dffe646465bb5bb8454c6143005859da Mon Sep 17 00:00:00 2001 From: iwubcode Date: Fri, 2 Jun 2023 22:02:37 -0500 Subject: [PATCH] VideoCommon: when loading a PNG with no custom texture data levels already, create a level, this avoids a potential segfault --- Source/Core/VideoCommon/Assets/CustomTextureData.cpp | 5 ----- Source/Core/VideoCommon/Assets/CustomTextureData.h | 1 - .../VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp | 7 +++++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Source/Core/VideoCommon/Assets/CustomTextureData.cpp b/Source/Core/VideoCommon/Assets/CustomTextureData.cpp index 26b65ad365..04183da3f0 100644 --- a/Source/Core/VideoCommon/Assets/CustomTextureData.cpp +++ b/Source/Core/VideoCommon/Assets/CustomTextureData.cpp @@ -515,11 +515,6 @@ bool LoadDDSTexture(CustomTextureData::Level* level, const std::string& filename info.first_mip_row_length, info.first_mip_size); } -bool LoadPNGTexture(CustomTextureData* texture, const std::string& filename) -{ - return LoadPNGTexture(&texture->m_levels[0], filename); -} - bool LoadPNGTexture(CustomTextureData::Level* level, const std::string& filename) { if (!level) [[unlikely]] diff --git a/Source/Core/VideoCommon/Assets/CustomTextureData.h b/Source/Core/VideoCommon/Assets/CustomTextureData.h index 9a16bf1db0..b7fd6f379e 100644 --- a/Source/Core/VideoCommon/Assets/CustomTextureData.h +++ b/Source/Core/VideoCommon/Assets/CustomTextureData.h @@ -27,6 +27,5 @@ public: bool LoadDDSTexture(CustomTextureData* texture, const std::string& filename); bool LoadDDSTexture(CustomTextureData::Level* level, const std::string& filename, u32 mip_level); -bool LoadPNGTexture(CustomTextureData* texture, const std::string& filename); bool LoadPNGTexture(CustomTextureData::Level* level, const std::string& filename); } // namespace VideoCommon diff --git a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp index 912def9e6b..f65ea9ccc9 100644 --- a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp +++ b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp @@ -72,8 +72,11 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass } else if (ext == ".png") { - LoadPNGTexture(data, asset_path.string()); - if (data->m_levels.empty()) [[unlikely]] + // If we have no levels, create one to pass into LoadPNGTexture + if (data->m_levels.empty()) + data->m_levels.push_back({}); + + if (!LoadPNGTexture(&data->m_levels[0], asset_path.string())) return {}; if (!LoadMips(asset_path, data)) return {};