Skip to content
Snippets Groups Projects

WIP: Whenever an image fails to load, it is defaulted to a 32x32 Fuchsia bitmap.

Closed Jan Delember requested to merge feature/#323_default_texture into master
2 unresolved threads
1 file
+ 13
2
Compare changes
  • Side-by-side
  • Inline
+ 13
2
@@ -22,6 +22,8 @@
#include "phx/image_loader.hpp"
#include <boost/filesystem.hpp>
#include <memory>
#include <string>
#include <utility>
@@ -41,8 +43,17 @@ std::unique_ptr<Resource> ImageLoader::Load(
declaration.dump());
return nullptr;
}
auto image =
std::make_unique<Image>(declaration["file_name"].get<std::string>());
auto filepath = declaration["file_name"].get<std::string>();
std::unique_ptr<Image> image;
if (boost::filesystem::exists(filepath.c_str()))
    • This only checks if the file exists. However, the file might fail to load for other reasons (e.g., it might be a corrupt file or an unsupported format)

      By Martin Bellgardt on 2018-03-27T08:27:53 (imported from GitLab)

      • FreeImage does not check whether a file is corrupt either (and it is not its job to do so), and crashes in that case. Which means the previous logic did not really change.

        Aside from this, boost::filesystem probably offers options for checking whether a file is valid. I will look into this.

        By Ali Can Demiralp on 2018-03-27T11:37:02 (imported from GitLab)

      • Please register or sign in to reply
Please register or sign in to reply
image = std::make_unique<Image>(filepath.c_str());
else
image = std::make_unique<Image>(
std::array<std::uint8_t, 4>{{255u, 0u, 255u, 255u}},
std::array<std::size_t, 2>{{32u, 32u}});
int bit_format = 32;
if (declaration.find("bit_format") == declaration.end() ||
!declaration["bit_format"].is_number_integer()) {
Loading