diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-16 22:56:42 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-16 22:56:42 +0100 |
commit | d33dbdff59693377d06d83225b0fe78c3168c464 (patch) | |
tree | b8a467f4cb6cea9c4ce3a50b6170dbce95542e7d /src | |
parent | 58c57578cae755422c35acfbbdf9ad399b4fd826 (diff) |
segmentation fault fixed
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/facade/Font.cpp | 7 | ||||
-rw-r--r-- | src/example/FontExample.cpp | 17 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp index 1ee3de1..333e500 100644 --- a/src/crepe/facade/Font.cpp +++ b/src/crepe/facade/Font.cpp @@ -10,10 +10,11 @@ Font::Font(const Asset & src, Mediator & mediator) font(nullptr, TTF_CloseFont) { Config & config = Config::get_instance(); const std::string FONT_PATH = src.get_path(); - TTF_Font * font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size); - if (font == NULL) + TTF_Font * loaded_font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size); + if (loaded_font == NULL) { throw runtime_error(format("Font: {} (path: {})", TTF_GetError(), FONT_PATH)); - this->font = {font, [](TTF_Font * font) { TTF_CloseFont(font); }}; + } + this->font = {loaded_font, [](TTF_Font * font) { TTF_CloseFont(font); }}; } TTF_Font * Font::get_font() const { return this->font.get(); } diff --git a/src/example/FontExample.cpp b/src/example/FontExample.cpp index 620cf8e..c2f21c4 100644 --- a/src/example/FontExample.cpp +++ b/src/example/FontExample.cpp @@ -7,7 +7,9 @@ #include <crepe/manager/EventManager.h> #include <crepe/api/Scene.h> #include <crepe/api/Script.h> +#include <crepe/api/LoopManager.h> #include <crepe/api/GameObject.h> +#include <crepe/api/Camera.h> #include <exception> #include <iostream> #include <memory> @@ -25,7 +27,7 @@ class TestScript : public Script{ auto now = steady_clock::now(); auto elapsed = duration_cast<seconds>(now - start_time).count(); - if (elapsed >= 1) { + if (elapsed >= 5) { Mediator& med = mediator; EventManager& event_mgr = med.event_manager; event_mgr.trigger_event<ShutDownEvent>(); @@ -37,15 +39,18 @@ class TestScene : public Scene{ void load_scene() override{ GameObject text_object = this->new_object("test","test",vec2{0,0},0,1); text_object.add_component<Text>(vec2(100, 100), vec2(0, 0), "test test", - "OpenSymbol", Text::Data{}); - text_object.add_component<BehaviorScript>(); + "Noto Sans", Text::Data{}); + text_object.add_component<BehaviorScript>().set_script<TestScript>(); + text_object.add_component<Camera>(ivec2{300,300},vec2{100,100},Camera::Data{ + }); } - std::string get_name(){ return "hey";} + std::string get_name() const override { return "hey"; } }; int main() { - - + LoopManager engine; + engine.add_scene<TestScene>(); + engine.start(); return 0; } |