Files
Crosspoint/src/components/UITheme.h
T
jpirnayandDave Allie 94198886d0 fix: prevent UITheme memory leak on theme reload (#975)
## Summary

- `UITheme::currentTheme` was a raw owning pointer with no destructor,
  causing a heap leak every time `setTheme()` was called (e.g. on
  theme change via settings reload)

## Additional Context

- Replaced `const BaseTheme*` with `std::unique_ptr<BaseTheme>` so the
  previous theme object is automatically deleted on reassignment
- Added `<memory>` include to `UITheme.h`; allocations updated to
  `std::make_unique<>` in `UITheme.cpp`

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_ (identified by
claude though)

---------

Co-authored-by: Dave Allie <dave@daveallie.com>
2026-02-19 22:13:12 +11:00

33 lines
949 B
C++

#pragma once
#include <functional>
#include <memory>
#include "CrossPointSettings.h"
#include "components/themes/BaseTheme.h"
class UITheme {
// Static instance
static UITheme instance;
public:
UITheme();
static UITheme& getInstance() { return instance; }
const ThemeMetrics& getMetrics() { return *currentMetrics; }
const BaseTheme& getTheme() { return *currentTheme; }
void reload();
void setTheme(CrossPointSettings::UI_THEME type);
static int getNumberOfItemsPerPage(const GfxRenderer& renderer, bool hasHeader, bool hasTabBar, bool hasButtonHints,
bool hasSubtitle);
static std::string getCoverThumbPath(std::string coverBmpPath, int coverHeight);
static UIIcon getFileIcon(std::string filename);
private:
const ThemeMetrics* currentMetrics;
std::unique_ptr<BaseTheme> currentTheme;
};
// Helper macro to access current theme
#define GUI UITheme::getInstance().getTheme()