From 71dda1921f50d68699035248c5f24648e549a53f Mon Sep 17 00:00:00 2001 From: chreden <4263940+chreden@users.noreply.github.com> Date: Sun, 5 Apr 2026 19:34:09 +0100 Subject: [PATCH] Track jumps in flybys to avoid infinite loops Make sure that when following jumps in flyby nodes we keep track of where we've already jumped from and to - if we've already done that jump just don't do it again. Prevents infinite loops. Closes #1562 --- trview.app/Elements/Flyby/Flyby.cpp | 32 ++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/trview.app/Elements/Flyby/Flyby.cpp b/trview.app/Elements/Flyby/Flyby.cpp index cd62da4dd..1e7d08121 100644 --- a/trview.app/Elements/Flyby/Flyby.cpp +++ b/trview.app/Elements/Flyby/Flyby.cpp @@ -6,6 +6,26 @@ namespace trview using namespace DirectX; using namespace DirectX::SimpleMath; + namespace + { + bool is_jump_taken(const std::unordered_map>& map, uint32_t source, uint32_t destination) + { + const auto source_found = map.find(source); + if (source_found == map.end()) + { + return false; + } + + const auto dest_found = std::ranges::find(source_found->second, destination); + if (dest_found == source_found->second.end()) + { + return false; + } + + return true; + } + } + IFlyby::~IFlyby() { } @@ -139,6 +159,7 @@ namespace trview std::vector> paths; paths.push_back({}); + std::unordered_map> jumps_taken; for (uint32_t n = 0; n < _camera_nodes.size() - 1; ++n) { CameraState state; @@ -146,9 +167,14 @@ namespace trview if (_camera_nodes[n]->flags() & 0x80) { - n = _camera_nodes[n]->timer(); - state.index = n; - paths.push_back({}); + const uint32_t next = _camera_nodes[n]->timer(); + if (!is_jump_taken(jumps_taken, n, next)) + { + jumps_taken[n].push_back(next); + n = next; + state.index = n; + paths.push_back({}); + } } for (int s = 0; s <= path_samples; ++s)