From d8d0af2bb3c7d0514f8a912d5e1bc6d6e4e77ffe Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 10 Mar 2024 21:03:53 +0100 Subject: [PATCH] rsx: Fix invalid iterator comparison (asserts on debug builds) Also make ranged_map::count const --- rpcs3/Emu/RSX/Common/ranged_map.hpp | 8 ++++---- rpcs3/Emu/RSX/Common/surface_store.h | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/ranged_map.hpp b/rpcs3/Emu/RSX/Common/ranged_map.hpp index fc236abe0b..8103e36972 100644 --- a/rpcs3/Emu/RSX/Common/ranged_map.hpp +++ b/rpcs3/Emu/RSX/Common/ranged_map.hpp @@ -128,7 +128,7 @@ namespace rsx public: bool operator == (const iterator& other) const { - return m_it == other.m_it; + return m_current == other.m_current && m_it == other.m_it; } auto* operator -> () @@ -183,10 +183,10 @@ namespace rsx m_data[block_for(range.start)].insert_or_assign(range.start, std::forward(value)); } - usz count(const u32 key) + usz count(const u32 key) const { - auto& block = m_data[block_for(key)]; - if (auto found = block.find(key); + const auto& block = m_data[block_for(key)]; + if (const auto found = block.find(key); found != block.end()) { return 1; diff --git a/rpcs3/Emu/RSX/Common/surface_store.h b/rpcs3/Emu/RSX/Common/surface_store.h index c51d1c30fe..e4062707d0 100644 --- a/rpcs3/Emu/RSX/Common/surface_store.h +++ b/rpcs3/Emu/RSX/Common/surface_store.h @@ -353,7 +353,7 @@ namespace rsx // If this surface has already been added via another descendant, just ignore it bool ignore = false; - for (auto &slice : new_surface->old_contents) + for (const auto& slice : new_surface->old_contents) { if (slice.source == surface) { @@ -374,8 +374,8 @@ namespace rsx surface == e.second) { // This has been 'swallowed' by the new surface and can be safely freed - auto &storage = surface->is_depth_surface() ? m_depth_stencil_storage : m_render_targets_storage; - auto &object = ::at32(storage, e.first); + auto& storage = surface->is_depth_surface() ? m_depth_stencil_storage : m_render_targets_storage; + auto& object = ::at32(storage, e.first); ensure(object); @@ -411,8 +411,9 @@ namespace rsx // Workaround. Preserve new surface tag value because pitch convert is unimplemented u64 new_content_tag = 0; - address_range *storage_bounds; - surface_ranged_map *primary_storage, *secondary_storage; + address_range* storage_bounds; + surface_ranged_map* primary_storage; + surface_ranged_map* secondary_storage; if constexpr (depth) { primary_storage = &m_depth_stencil_storage; @@ -430,7 +431,7 @@ namespace rsx auto It = primary_storage->find(address); if (It != primary_storage->end()) { - surface_storage_type &surface = It->second; + surface_storage_type& surface = It->second; const bool pitch_compatible = Traits::surface_is_pitch_compatible(surface, pitch); if (!pitch_compatible)