From 7e6ca1097b1f80006b792eac31d9a46454fb5bd3 Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Sun, 4 Jun 2023 18:17:55 -0700 Subject: [PATCH] ui: Only check for xbe if snapshot xbe filter is on --- ui/xui/main-menu.cc | 31 +++++++++++++++++++++---------- ui/xui/main-menu.hh | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ui/xui/main-menu.cc b/ui/xui/main-menu.cc index 79ab0dbb67..c99f9ed10b 100644 --- a/ui/xui/main-menu.cc +++ b/ui/xui/main-menu.cc @@ -647,13 +647,11 @@ MainMenuSnapshotsView::MainMenuSnapshotsView() : MainMenuTabView() xemu_snapshots_mark_dirty(); m_search_regex = NULL; - m_current_title_name = NULL; m_current_title_id = 0; } MainMenuSnapshotsView::~MainMenuSnapshotsView() { - g_free(m_current_title_name); g_free(m_search_regex); } @@ -778,17 +776,30 @@ void MainMenuSnapshotsView::Draw() { g_snapshot_mgr.Refresh(); - struct xbe *xbe = xemu_get_xbe_info(); - if (xbe && xbe->cert->m_titleid != m_current_title_id) { - g_free(m_current_title_name); - m_current_title_name = g_utf16_to_utf8(xbe->cert->m_title_name, 40, NULL, NULL, NULL); - m_current_title_id = xbe->cert->m_titleid; - } - SectionTitle("Snapshots"); Toggle("Filter by current title", &g_config.general.snapshots.filter_current_game, "Only display snapshots created while running the currently running XBE"); + if (g_config.general.snapshots.filter_current_game) { + struct xbe *xbe = xemu_get_xbe_info(); + if (xbe && xbe->cert) { + if (xbe->cert->m_titleid != m_current_title_id) { + char *title_name = g_utf16_to_utf8(xbe->cert->m_title_name, 40, NULL, NULL, NULL); + if (title_name) { + m_current_title_name = title_name; + g_free(title_name); + } else { + m_current_title_name.clear(); + } + + m_current_title_id = xbe->cert->m_titleid; + } + } else { + m_current_title_name.clear(); + m_current_title_id = 0; + } + } + ImGui::SetNextItemWidth(ImGui::GetColumnWidth() * 0.8); ImGui::PushFont(g_font_mgr.m_menu_font_small); ImGui::InputTextWithHint("##search", "Search or name new snapshot...", @@ -826,7 +837,7 @@ void MainMenuSnapshotsView::Draw() for (int i = g_snapshot_mgr.m_snapshots_len - 1; i >= 0; i--) { if (g_config.general.snapshots.filter_current_game && g_snapshot_mgr.m_extra_data[i].xbe_title_name && - (strcmp(m_current_title_name, g_snapshot_mgr.m_extra_data[i].xbe_title_name) != 0)) { + m_current_title_name.size() && strcmp(m_current_title_name.c_str(), g_snapshot_mgr.m_extra_data[i].xbe_title_name)) { continue; } diff --git a/ui/xui/main-menu.hh b/ui/xui/main-menu.hh index 0c769a3c5b..63c4040fd0 100644 --- a/ui/xui/main-menu.hh +++ b/ui/xui/main-menu.hh @@ -105,7 +105,7 @@ class MainMenuSnapshotsView : public virtual MainMenuTabView { protected: uint32_t m_current_title_id; - char *m_current_title_name; + std::string m_current_title_name; std::string m_search_buf; private: