Merge pull request #11879 from iwubcode/texture_data_load_nolevels

VideoCommon: avoid segfault when loading a PNG with no custom texture data levels
This commit is contained in:
Admiral H. Curtiss 2023-06-03 19:35:48 +02:00 committed by GitHub
commit 80bf175c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 8 deletions

View File

@ -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]]

View File

@ -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

View File

@ -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 {};