| 26 | } |
| 27 | |
| 28 | void AudioOutputRouter::setCurrentDevice(const QAudioDevice& dev) |
| 29 | { |
| 30 | m_device = dev; |
| 31 | // Fan out over a snapshot: a follower's setOutputDevice() could register |
| 32 | // another follower (or otherwise mutate m_followers) during the callback, |
| 33 | // which would invalidate a live iterator / reallocate the vector mid-loop. |
| 34 | // A follower added during the fan-out is already seeded by registerFollower(), |
| 35 | // so skipping it here is correct, not a miss. The list is tiny (registered |
| 36 | // once at startup) so the copy is negligible. |
| 37 | const auto followers = m_followers; |
| 38 | for (const auto& f : followers) { |
| 39 | if (f.apply) |
| 40 | f.apply(m_device); // guarded followers self-skip when their QPointer is null |
| 41 | } |
| 42 | // Prune followers whose QPointer guard has gone null so dead entries don't |
| 43 | // accumulate over the router's lifetime (#3660). Done after the fan-out on |
| 44 | // the live vector; a follower added re-entrantly during the loop is alive |
| 45 | // and therefore kept. Raw std::function followers have no `alive` predicate |
| 46 | // and are never pruned (the caller owns their lifetime). |
| 47 | std::erase_if(m_followers, [](const Follower& f) { |
| 48 | return f.alive && !f.alive(); |
| 49 | }); |
| 50 | } |
| 51 | |
| 52 | } // namespace AetherSDR |
no outgoing calls