Merge pull request #22170 from hrydgard/upnp-portmanager-fixes

UPnP: fix the exit hang and the CPU spin, and only run the thread when enabled
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2026-08-30 10:25:44 +02:00
commit 76c7ddfb11
5 files changed
+590 -427

No files matched your search

+7 -3
View File
@@ -1049,9 +1049,13 @@ void GameSettingsScreen::CreateNetworkingSettings(UI::ViewGroup *networkingSetti
dnsServer->SetDisabledPtr(&g_Config.bInfrastructureAutoDNS);
networkingSettings->Add(new ItemHeader(n->T("UPnP (port-forwarding)")));
networkingSettings->Add(new CheckBox(&g_Config.bEnableUPnP, n->T("Enable UPnP", "Enable UPnP (need a few seconds to detect)")))->OnClick.Add([](UI::EventParams &e) {
// Wake the UPnP service thread immediately so it reacts to the new setting instead
// of waiting for the next periodic retry (or a port request that may never come).
// Only togglable outside a game - sceNet latches settings like UPnPUseOriginalPort at boot,
// and a game that's already mapped its ports wouldn't cope with them disappearing.
CheckBox *enableUPnP = networkingSettings->Add(new CheckBox(&g_Config.bEnableUPnP, n->T("Enable UPnP", "Enable UPnP (need a few seconds to detect)")));
enableUPnP->SetEnabled(!PSP_IsInited());
enableUPnP->OnClick.Add([](UI::EventParams &e) {
// Wake the UPnP service thread so it connects (or tears its mappings back down) right
// away, instead of waiting for a port request that may never come.
UPnP_Notify();
});
auto *useOriPort = networkingSettings->Add(new CheckBox(&g_Config.bUPnPUseOriginalPort, n->T("UPnP use original port", "UPnP use original port (Enabled = PSP compatibility)")));
+5 -5
View File
@@ -515,9 +515,6 @@ void NativeInit(int argc, const char *argv[], const CommandLineOptions &cmdLineO
IncrementDebugCounter(DebugCounter::APP_BOOT);
// Probably an excessive timeout. it only causes delays on shutdown, though.
__UPnPInit(2000);
ShaderTranslationInit();
g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count);
@@ -704,6 +701,11 @@ void NativeInit(int argc, const char *argv[], const CommandLineOptions &cmdLineO
g_Config.LoadAppendedConfig();
}
// Has to be after the config is loaded: it only starts a service thread if UPnP is enabled,
// and g_Config.Init() above doesn't read the ini, it just builds a lookup table.
// Probably an excessive timeout. It only causes delays on shutdown, though.
__UPnPInit(2000);
// This parameter should be a boot filename. Only accept it if we
// don't already have one.
if (!cmdLineOptions.bootFilenames.empty()) {
@@ -1851,8 +1853,6 @@ void NativeShutdown() {
__UPnPShutdown();
g_PortManager.Shutdown();
net::Shutdown();
g_Discord.Shutdown();