Skip to content

Commit

Permalink
Avoid crash if branding fails to load. (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robadob authored Mar 31, 2023
1 parent dea46cd commit d41958f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/flamegpu/visualiser/Visualiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "flamegpu/visualiser/ui/SplashScreen.h"
#include "flamegpu/visualiser/multipass/FrameBuffer.h"
#include "flamegpu/visualiser/multipass/FrameBufferAttachment.h"
#include "util/Resources.h"

namespace flamegpu {
namespace visualiser {
Expand Down Expand Up @@ -1230,7 +1231,13 @@ void Visualiser::screenshot(const bool verbose) {
void Visualiser::setWindowIcon() {
if (!window)
return;
auto surface = Texture::loadImage(modelConfig.isPython ? "resources/pyflamegpu_icon.png" : "resources/flamegpu_icon.png");
std::shared_ptr<SDL_Surface> surface;
try {
surface = Texture::loadImage(modelConfig.isPython ? "resources/pyflamegpu_icon.png" : "resources/flamegpu_icon.png");
} catch(...) {
// Fail silently, branding is not required
fprintf(stderr, "Failed to load window icon: %s\n", Resources::locateFile(modelConfig.isPython ? "resources/pyflamegpu_icon.png" : "resources/flamegpu_icon.png").c_str());
}
if (surface)
SDL_SetWindowIcon(window, surface.get());
}
Expand Down
22 changes: 17 additions & 5 deletions src/flamegpu/visualiser/ui/SplashScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,36 @@
#include "flamegpu/visualiser/ui/Sprite2D.h"
#include "flamegpu/visualiser/ui/Text.h"
#include "flamegpu/visualiser/util/fonts.h"
#include "flamegpu/visualiser/util/Resources.h"

namespace flamegpu {
namespace visualiser {

SplashScreen::SplashScreen(const glm::vec3& textColor, const std::string& message, bool isPython)
: logo_offset(0)
, text_offset(0) {
logo = std::make_shared<Sprite2D>(Texture2D::load(isPython ? "resources/pyflamegpu.png" : "resources/flamegpu.png"));
int logo_height = 0;
try {
logo = std::make_shared<Sprite2D>(Texture2D::load(isPython ? "resources/pyflamegpu.png" : "resources/flamegpu.png"));
logo_height = logo->getHeight();
} catch(...) {
// Fail silently, branding is not required
fprintf(stderr, "Failed to load splash screen logo: %s\n", Resources::locateFile(isPython ? "resources/pyflamegpu.png" : "resources/flamegpu.png").c_str());
}
text = std::make_shared<Text>("Loading...", 45, textColor, fonts::findFont({ "Arial" }, fonts::GenericFontFamily::SANS).c_str());
// Calculate offsets for vertical stacking
const int PADDING = 10;
const int FULL_HEIGHT = logo->getHeight() + PADDING + text->getHeight();
const int FULL_HEIGHT = logo_height + PADDING + text->getHeight();
const int MID_HEIGHT = FULL_HEIGHT / 2;
logo_offset.y = MID_HEIGHT - (logo->getHeight() / 2);
text_offset.y = MID_HEIGHT - (logo->getHeight() + PADDING + (text->getHeight() / 2));
logo_offset.y = MID_HEIGHT - (logo_height / 2);
text_offset.y = MID_HEIGHT - (logo_height + PADDING + (text->getHeight() / 2));
}
std::vector<SplashScreen::OverlayItem> SplashScreen::getOverlays() const {
return std::vector<OverlayItem>{OverlayItem{ logo, logo_offset, 0 }, OverlayItem{ text, text_offset, 0 }};
if (logo) {
return std::vector<OverlayItem>{OverlayItem{ logo, logo_offset, 0 }, OverlayItem{ text, text_offset, 0 }};
} else {
return std::vector<OverlayItem>{OverlayItem{ text, text_offset, 0 }};
}
}

} // namespace visualiser
Expand Down

0 comments on commit d41958f

Please sign in to comment.