From e798c8fab239896a5d8072c135a8a4f08c09fc14 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:12:16 -0400 Subject: [PATCH] PortMappingManager: Additional sanity checks --- lib/netplay/port_mapping_manager.cpp | 13 +++++++++---- lib/netplay/port_mapping_manager.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/netplay/port_mapping_manager.cpp b/lib/netplay/port_mapping_manager.cpp index f4161ab2b00..c5bb7e2b736 100644 --- a/lib/netplay/port_mapping_manager.cpp +++ b/lib/netplay/port_mapping_manager.cpp @@ -88,6 +88,7 @@ bool PortMappingManager::PortMappingAsyncRequest::timed_out(TimePoint t) const void PortMappingManager::PortMappingAsyncRequest::set_port_mapping_in_progress(TimePoint deadline_, MappingId mappingId_, const std::shared_ptr& impl_) { ASSERT(s == PortMappingDiscoveryStatus::NOT_STARTED || s == PortMappingDiscoveryStatus::IN_PROGRESS, "Invalid state"); + ASSERT(impl_ != nullptr, "Missing impl?"); deadline = deadline_; s = PortMappingDiscoveryStatus::IN_PROGRESS; mappingId = mappingId_; @@ -99,6 +100,7 @@ bool PortMappingManager::PortMappingAsyncRequest::destroy_mapping() // Destroy the internal mapping. if (mappingId != WZ_PORT_MAPPING_ID_INVALID) { + ASSERT_OR_RETURN(false, impl != nullptr, "Missing impl?"); const auto result = impl->destroy_port_mapping(mappingId); mappingId = WZ_PORT_MAPPING_ID_INVALID; s = PortMappingDiscoveryStatus::NOT_STARTED; @@ -145,7 +147,7 @@ bool PortMappingManager::switchToNextWorkingImpl(PortMappingImpl::Type startingT { currImplTypeIdx_ = startingTypeIdx; currentImpl_ = newImpl; - loadedImpls.push_back(newImpl); + loadedImpls_.push_back(newImpl); return true; } startingTypeIdx = nextImplType(startingTypeIdx); @@ -173,12 +175,15 @@ void PortMappingManager::shutdown() return; } - currentImpl_->shutdown(); - for (auto impl : loadedImpls) + if (currentImpl_) + { + currentImpl_->shutdown(); + } + for (auto impl : loadedImpls_) { impl->shutdown(); } - loadedImpls.clear(); + loadedImpls_.clear(); currentImpl_ = nullptr; { diff --git a/lib/netplay/port_mapping_manager.h b/lib/netplay/port_mapping_manager.h index ace6514eee9..94622bce4d6 100644 --- a/lib/netplay/port_mapping_manager.h +++ b/lib/netplay/port_mapping_manager.h @@ -247,7 +247,7 @@ class PortMappingManager std::unordered_map successfulRequests_; bool isInit_ = false; - std::vector> loadedImpls; + std::vector> loadedImpls_; std::shared_ptr currentImpl_ = nullptr; PortMappingImpl::Type currImplTypeIdx_ = PortMappingImpl::Type::Libplum;