VERY experimental Nintendo Switch 2 emulator
C++
[applet] add post exit cleanups to frontend applets to avoid accumulation (#4457)
xbzk847e91c3a8ca
diff --git a/src/core/hle/service/am/frontend/applets.cpp b/src/core/hle/service/am/frontend/applets.cppindex 407ca10602..d622c7b7a7 100644--- a/src/core/hle/service/am/frontend/applets.cpp+++ b/src/core/hle/service/am/frontend/applets.cpp@@ -29,6 +29,7 @@#include "core/hle/service/am/frontend/applet_web_browser.h"#include "core/hle/service/am/frontend/applets.h"#include "core/hle/service/am/service/storage.h"+#include "core/hle/service/am/window_system.h"#include "core/hle/service/sm/sm.h"namespace Service::AM::Frontend {@@ -72,10 +73,16 @@ void FrontendApplet::PushInteractiveOutData(std::shared_ptr<IStorage> storage) {void FrontendApplet::Exit() {auto applet_ = applet.lock();-- std::scoped_lock lk{applet_->lock};- applet_->is_completed = true;- applet_->state_changed_event.Signal(system.Kernel());+ {+ std::scoped_lock lk{applet_->lock};+ applet_->is_completed = true;+ applet_->state_changed_event.Signal(system.Kernel());+ }+ if (auto caller_applet = applet_->caller_applet.lock()) {+ std::scoped_lock lk{caller_applet->lock};+ std::erase(caller_applet->child_applets, applet_);+ }+ if (auto* window_system = system.GetAppletManager().GetWindowSystem()) window_system->RequestUpdate();}FrontendAppletSet::FrontendAppletSet() = default;diff --git a/src/core/hle/service/am/service/library_applet_creator.cpp b/src/core/hle/service/am/service/library_applet_creator.cppindex ce80ce946f..4ee92908b5 100644--- a/src/core/hle/service/am/service/library_applet_creator.cpp+++ b/src/core/hle/service/am/service/library_applet_creator.cpp@@ -122,7 +122,10 @@ std::shared_ptr<ILibraryAppletAccessor> CreateGuestApplet(Core::System& system,auto broker = std::make_shared<AppletDataBroker>(system);applet->caller_applet = caller_applet;applet->caller_applet_broker = broker;- caller_applet->child_applets.push_back(applet);+ {+ std::scoped_lock lk{caller_applet->lock};+ caller_applet->child_applets.push_back(applet);+ }window_system.TrackApplet(applet, false);return std::make_shared<ILibraryAppletAccessor>(system, broker, applet);}@@ -148,10 +151,10 @@ std::shared_ptr<ILibraryAppletAccessor> CreateFrontendApplet(Core::System& systeapplet->caller_applet = caller_applet;applet->caller_applet_broker = storage;applet->frontend = system.GetFrontendAppletHolder().GetApplet(applet, applet_id, mode);- caller_applet->child_applets.push_back(applet);-- window_system.TrackApplet(applet, false);-+ {+ std::scoped_lock lk{caller_applet->lock};+ caller_applet->child_applets.push_back(applet);+ }return std::make_shared<ILibraryAppletAccessor>(system, storage, applet);}