fix deko3d mem leak when using docked mode

fixes #97
This commit is contained in:
ITotalJustice
2025-01-16 21:24:21 +00:00
parent 5612ae5691
commit b6304fca75

View File

@@ -45,6 +45,11 @@ struct ThemeIdPair {
ElementType type{ElementType::None}; ElementType type{ElementType::None};
}; };
struct FrameBufferSize {
Vec2 size;
Vec2 scale;
};
constexpr ThemeIdPair THEME_ENTRIES[] = { constexpr ThemeIdPair THEME_ENTRIES[] = {
{ "background", ThemeEntryID_BACKGROUND }, { "background", ThemeEntryID_BACKGROUND },
{ "grid", ThemeEntryID_GRID }, { "grid", ThemeEntryID_GRID },
@@ -223,6 +228,26 @@ void appplet_hook_calback(AppletHookType type, void *param) {
} }
} }
auto GetFrameBufferSize() -> FrameBufferSize {
FrameBufferSize fb{};
switch (appletGetOperationMode()) {
case AppletOperationMode_Handheld:
fb.size.x = 1280;
fb.size.y = 720;
break;
case AppletOperationMode_Console:
fb.size.x = 1920;
fb.size.y = 1080;
break;
}
fb.scale.x = fb.size.x / SCREEN_WIDTH;
fb.scale.y = fb.size.y / SCREEN_HEIGHT;
return fb;
}
// this will try to decompress the icon and then re-convert it to jpg // this will try to decompress the icon and then re-convert it to jpg
// in order to strip exif data. // in order to strip exif data.
// this doesn't take long at all, but it's very overkill. // this doesn't take long at all, but it's very overkill.
@@ -430,24 +455,12 @@ void App::Loop() {
}, event.value()); }, event.value());
} }
u32 w{},h{}; const auto fb = GetFrameBufferSize();
switch (appletGetOperationMode()) { if (fb.size.x != s_width || fb.size.y != s_height) {
case AppletOperationMode_Handheld: s_width = fb.size.x;
w = 1280; s_height = fb.size.y;
h = 720; m_scale = fb.scale;
break; this->destroyFramebufferResources();
case AppletOperationMode_Console:
w = 1920;
h = 1080;
break;
}
if (w != s_width || h != s_height) {
s_width = w;
s_height = h;
m_scale.x = (float)s_width / SCREEN_WIDTH;
m_scale.y = (float)s_height / SCREEN_HEIGHT;
this->createFramebufferResources(); this->createFramebufferResources();
renderer->UpdateViewSize(s_width, s_height); renderer->UpdateViewSize(s_width, s_height);
} }
@@ -1210,6 +1223,12 @@ App::App(const char* argv0) {
curl::Init(); curl::Init();
// get current size of the framebuffer
const auto fb = GetFrameBufferSize();
s_width = fb.size.x;
s_height = fb.size.y;
m_scale = fb.scale;
// Create the deko3d device // Create the deko3d device
this->device = dk::DeviceMaker{} this->device = dk::DeviceMaker{}
.setCbDebug(deko3d_error_cb) .setCbDebug(deko3d_error_cb)
@@ -1233,7 +1252,7 @@ App::App(const char* argv0) {
// Create the framebuffer resources // Create the framebuffer resources
this->createFramebufferResources(); this->createFramebufferResources();
this->renderer.emplace(SCREEN_WIDTH, SCREEN_HEIGHT, this->device, this->queue, *this->pool_images, *this->pool_code, *this->pool_data); this->renderer.emplace(s_width, s_height, this->device, this->queue, *this->pool_images, *this->pool_code, *this->pool_data);
this->vg = nvgCreateDk(&*this->renderer, NVG_ANTIALIAS | NVG_STENCIL_STROKES); this->vg = nvgCreateDk(&*this->renderer, NVG_ANTIALIAS | NVG_STENCIL_STROKES);
i18n::init(GetLanguage()); i18n::init(GetLanguage());