Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11879 from iwubcode/texture_data_load_nolevels
VideoCommon: avoid segfault when loading a PNG with no custom texture data levels
  • Loading branch information
AdmiralCurtiss committed Jun 3, 2023
2 parents 0b3d28a + 47c40d5 commit 80bf175
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
5 changes: 0 additions & 5 deletions Source/Core/VideoCommon/Assets/CustomTextureData.cpp
Expand Up @@ -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]]
Expand Down
1 change: 0 additions & 1 deletion Source/Core/VideoCommon/Assets/CustomTextureData.h
Expand Up @@ -27,6 +27,5 @@ class CustomTextureData

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

0 comments on commit 80bf175

Please sign in to comment.