From d5af4c9baf3fac6ac7e7515c12d90ce859d51c7f Mon Sep 17 00:00:00 2001 From: Slendi Date: Fri, 10 Oct 2025 17:25:42 +0300 Subject: [PATCH] Fix crash Signed-off-by: Slendi --- CMakeLists.txt | 2 +- src/App.cpp | 11 ++++++++++- src/App.hpp | 19 +++++++++++++++++++ src/Tick.cpp | 5 +++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 736a542..8d26b20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,7 +162,7 @@ target_link_libraries(waylight PRIVATE PkgConfig::XKBCOMMON PkgConfig::FONTCONFIG PkgConfig::HARFBUZZ - + raylib msdfgen::msdfgen-core msdfgen::msdfgen-ext diff --git a/src/App.cpp b/src/App.cpp index a9a608d..14d5ece 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -146,6 +146,10 @@ App::~App() if (m_sfd != -1) close(m_sfd); + for (auto &[_, tex] : m_textures) { + UnloadTexture(tex); + } + destroy_layer_surface(); if (m_gl.edpy != EGL_NO_DISPLAY) { @@ -597,7 +601,12 @@ auto App::init_wayland() -> void if (!ctx->data.empty()) ctx->app->m_clipboard_cache = std::move(ctx->data); - wl_data_offer_destroy(ctx->offer); + if (ctx->offer + == ctx->app->m_wayland.curr_offer) { + wl_data_offer_destroy(ctx->offer); + ctx->app->m_wayland.curr_offer + = nullptr; + } delete ctx; return G_SOURCE_REMOVE; }, diff --git a/src/App.hpp b/src/App.hpp index c8dc542..b08d3ee 100644 --- a/src/App.hpp +++ b/src/App.hpp @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include #include @@ -196,6 +198,23 @@ private: bool surrounding_dirty { false }; } m_ime; + // NOTE: Canonicalize first! + std::unordered_map m_textures; + + auto get_texture(std::filesystem::path const &path) -> Texture2D const & + { + if (m_textures.contains(path)) { + return m_textures[path]; + } + auto fname = path.c_str(); + assert(fname); + TraceLog(LOG_INFO, std::format("loading texture at {}", fname).c_str()); + auto const tex = LoadTexture(fname); + assert(IsTextureValid(tex)); + m_textures[path] = tex; + return m_textures[path]; + } + enum_array m_themes { make_default_themes() }; Theme m_active_theme { Theme::Light }; diff --git a/src/Tick.cpp b/src/Tick.cpp index 0238c86..7576249 100644 --- a/src/Tick.cpp +++ b/src/Tick.cpp @@ -8,6 +8,9 @@ #include #include +#include +#include + auto App::tick() -> void { static std::pmr::string text_input_data {}; @@ -62,6 +65,8 @@ auto App::tick() -> void update_text_input_state(text_input_data, 1, input_rect); } + // DrawTexture(get_texture(*icon_lookup("folder", 32)), 50, 50, WHITE); + EndDrawing(); eglSwapBuffers(m_gl.edpy, m_gl.esurf);