Skip to content

Commit

Permalink
Merge pull request #5 from marcusklang/marcusklang-texturedata-patch
Browse files Browse the repository at this point in the history
Fixed getTextureData() when failed to load texture
  • Loading branch information
pierremoreau authored Jan 8, 2020
2 parents eb92a7f + fa66f28 commit 238c70b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ getTextureData(std::string const& filename, u32& width, u32& height, bool flip)
auto const path = config::resources_path(filename);
auto const channels_nb = 4u;
unsigned char* image_data = stbi_load(path.c_str(), reinterpret_cast<int*>(&width), reinterpret_cast<int*>(&height), nullptr, channels_nb);
std::vector<unsigned char> image(width * height * channels_nb);
if (image_data == nullptr) {
LogWarning("Couldn't load or decode image file %s", path.c_str());
return image;

// Provide a small empty image instead in case of failure.
width = 16;
height = 16;
return std::vector<unsigned char>(width * height * channels_nb);
}

std::vector<unsigned char> image(width * height * channels_nb);
if (!flip) {
std::memcpy(image.data(), image_data, image.size());
stbi_image_free(image_data);
Expand Down

0 comments on commit 238c70b

Please sign in to comment.