From fbf53686c37a4b04453c6082ccf273417fcb0a87 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Tue, 21 Mar 2023 09:07:49 -0700 Subject: [PATCH] apt: Fix exiting to game list on application close. (#6353) --- src/core/hle/kernel/thread.cpp | 5 ++-- src/core/hle/service/apt/applet_manager.cpp | 29 ++++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 67bcdd4be..0e4c6e370 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -108,8 +108,9 @@ void Thread::Stop() { u32 tls_page = (tls_address - Memory::TLS_AREA_VADDR) / Memory::CITRA_PAGE_SIZE; u32 tls_slot = ((tls_address - Memory::TLS_AREA_VADDR) % Memory::CITRA_PAGE_SIZE) / Memory::TLS_ENTRY_SIZE; - ASSERT(owner_process.lock()); - owner_process.lock()->tls_slots[tls_page].reset(tls_slot); + if (auto process = owner_process.lock()) { + process->tls_slots[tls_page].reset(tls_slot); + } } void ThreadManager::SwitchContext(Thread* new_thread) { diff --git a/src/core/hle/service/apt/applet_manager.cpp b/src/core/hle/service/apt/applet_manager.cpp index b0755bfdb..8e21be2f2 100644 --- a/src/core/hle/service/apt/applet_manager.cpp +++ b/src/core/hle/service/apt/applet_manager.cpp @@ -882,7 +882,12 @@ ResultCode AppletManager::PrepareToCloseApplication(bool return_to_sys) { } if (application_close_target == AppletSlot::HomeMenu) { - EnsureHomeMenuLoaded(); + // Real APT would make sure home menu is loaded here. However, this is only really + // needed if the home menu wasn't loaded in the first place. Since we want to + // preserve normal behavior when the user loaded the game directly without going + // through home menu, we skip this. Then, later we just close to the game list + // when the application finishes closing. + // EnsureHomeMenuLoaded(); } return RESULT_SUCCESS; @@ -896,15 +901,21 @@ ResultCode AppletManager::CloseApplication(std::shared_ptr objec GetAppletSlot(AppletSlot::Application)->Reset(); if (application_close_target != AppletSlot::Error) { - active_slot = application_close_target; + // If exiting to the home menu and it is not loaded, exit to game list. + if (application_close_target == AppletSlot::HomeMenu && + !GetAppletSlot(application_close_target)->registered) { + system.RequestShutdown(); + } else { + active_slot = application_close_target; - CancelAndSendParameter({ - .sender_id = AppletId::Application, - .destination_id = GetAppletSlot(application_close_target)->applet_id, - .signal = SignalType::WakeupByExit, - .object = std::move(object), - .buffer = buffer, - }); + CancelAndSendParameter({ + .sender_id = AppletId::Application, + .destination_id = GetAppletSlot(application_close_target)->applet_id, + .signal = SignalType::WakeupByExit, + .object = std::move(object), + .buffer = buffer, + }); + } } // TODO: Terminate the application process.