mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
fix: opengl resource delete error
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "Cubed/ui/widget.hpp"
|
||||
|
||||
#include <format>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Cubed {
|
||||
@@ -12,6 +13,7 @@ namespace Cubed {
|
||||
class DebugCollector {
|
||||
public:
|
||||
static DebugCollector& get();
|
||||
static void distory();
|
||||
DebugCollector();
|
||||
|
||||
void report(const std::string& name, std::string_view content);
|
||||
@@ -22,6 +24,7 @@ public:
|
||||
private:
|
||||
ColumnLayout m_widget;
|
||||
std::unordered_map<std::string, Label*> m_component;
|
||||
static std::unique_ptr<DebugCollector>& get_ptr();
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
Font();
|
||||
~Font();
|
||||
static Font& get();
|
||||
|
||||
static void destroy();
|
||||
TextMesh vertices(const std::string& text);
|
||||
const Texture* text_texture();
|
||||
static const std::string& font_path();
|
||||
@@ -70,6 +72,7 @@ private:
|
||||
int m_max_layers = 0;
|
||||
Glyph& load_glyph(uint32_t glyph_index);
|
||||
void upload_glyph(Glyph& glyph, const unsigned char* buffer);
|
||||
static std::unique_ptr<Font>& get_ptr();
|
||||
};
|
||||
|
||||
} // namespace Cubed
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Cubed/localization.hpp"
|
||||
#include "Cubed/tools/arg_parser.hpp"
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
#include "Cubed/tools/font.hpp"
|
||||
#include "Cubed/tools/log.hpp"
|
||||
#include "Cubed/tools/system_info.hpp"
|
||||
#include "Cubed/tools/system_locate.hpp"
|
||||
@@ -13,6 +14,7 @@
|
||||
|
||||
#include <exception>
|
||||
#include <imgui_impl_sdl3.h>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
App::App()
|
||||
@@ -21,7 +23,11 @@ App::App()
|
||||
m_texture_manager(m_game_config), m_audio(m_game_config),
|
||||
m_renderer(m_texture_manager, m_game_config), m_scene_manager(*this) {}
|
||||
|
||||
App::~App() { stop_text_input(); }
|
||||
App::~App() {
|
||||
stop_text_input();
|
||||
Font::destroy();
|
||||
DebugCollector::distory();
|
||||
}
|
||||
|
||||
void App::init(int argc, char** argv) {
|
||||
handle_argument(argc, argv);
|
||||
|
||||
@@ -4,16 +4,19 @@
|
||||
#include "version.hpp"
|
||||
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <memory>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
DebugCollector::DebugCollector() : m_widget(nullptr) {}
|
||||
|
||||
DebugCollector& DebugCollector::get() {
|
||||
static DebugCollector instance;
|
||||
DebugCollector& DebugCollector::get() { return *get_ptr(); }
|
||||
std::unique_ptr<DebugCollector>& DebugCollector::get_ptr() {
|
||||
static std::unique_ptr<DebugCollector> instance =
|
||||
std::make_unique<DebugCollector>();
|
||||
return instance;
|
||||
}
|
||||
|
||||
void DebugCollector::distory() { get_ptr().reset(); }
|
||||
void DebugCollector::init(int width, int height) {
|
||||
constexpr float SCALE = 0.6f;
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
#include "Cubed/tools/log.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace Cubed {
|
||||
@@ -72,10 +75,13 @@ void Font::upload_glyph(Glyph& glyph, const unsigned char* buffer) {
|
||||
glyph.size.y / float(CELL_SIZE)};
|
||||
}
|
||||
|
||||
Font& Font::get() {
|
||||
static Font font;
|
||||
Font& Font::get() { return *get_ptr(); }
|
||||
std::unique_ptr<Font>& Font::get_ptr() {
|
||||
static std::unique_ptr<Font> font = std::make_unique<Font>();
|
||||
return font;
|
||||
}
|
||||
void Font::destroy() { get_ptr().reset(); }
|
||||
|
||||
TextMesh Font::vertices(const std::string& text) {
|
||||
|
||||
hb_buffer_t* buffer = hb_buffer_create();
|
||||
|
||||
Reference in New Issue
Block a user