Browse Source

Fail gracefully if APP->window->loadFont()/loadImage() is called from a ModuleWidget constructor when Window is null.

tags/v2.0.3
Andrew Belt 3 years ago
parent
commit
9dcb2e66bf
1 changed files with 8 additions and 0 deletions
  1. +8
    -0
      src/window/Window.cpp

+ 8
- 0
src/window/Window.cpp View File

@@ -709,6 +709,10 @@ double Window::getFrameDurationRemaining() {




std::shared_ptr<Font> Window::loadFont(const std::string& filename) { std::shared_ptr<Font> Window::loadFont(const std::string& filename) {
// HACK If ModuleWidgets call loadFont() in their constructor, APP->window might be null.
if (!this)
return NULL;

const auto& pair = internal->fontCache.find(filename); const auto& pair = internal->fontCache.find(filename);
if (pair != internal->fontCache.end()) if (pair != internal->fontCache.end())
return pair->second; return pair->second;
@@ -729,6 +733,10 @@ std::shared_ptr<Font> Window::loadFont(const std::string& filename) {




std::shared_ptr<Image> Window::loadImage(const std::string& filename) { std::shared_ptr<Image> Window::loadImage(const std::string& filename) {
// HACK If ModuleWidgets call loadFont() in their constructor, APP->window might be null.
if (!this)
return NULL;

const auto& pair = internal->imageCache.find(filename); const auto& pair = internal->imageCache.find(filename);
if (pair != internal->imageCache.end()) if (pair != internal->imageCache.end())
return pair->second; return pair->second;


Loading…
Cancel
Save