| 69 | } |
| 70 | |
| 71 | void StageManager::sync() { |
| 72 | std::unordered_set<std::string> live_names; |
| 73 | live_names.reserve(model_.size()); |
| 74 | |
| 75 | for (std::size_t i = 0; i < model_.size(); ++i) { |
| 76 | const std::string& name = model_.variable_name_of(i); |
| 77 | const std::uint64_t rev = model_.revision_of(i); |
| 78 | live_names.insert(name); |
| 79 | |
| 80 | const auto it = by_name_.find(name); |
| 81 | if (it == by_name_.end()) { |
| 82 | // New buffer. On initialize() failure, log and leave no entry |
| 83 | // so a later frame can retry once the underlying cause (e.g. |
| 84 | // GL context) is resolved. |
| 85 | // |
| 86 | // The empty callback is Stage's on_render_update hook (used by |
| 87 | // the legacy Qt frontend to request a repaint -- see tag |
| 88 | // legacy-qt); the ImGui host already redraws every frame |
| 89 | // unconditionally, so there is nothing for it to trigger here. |
| 90 | auto stage = std::make_unique<oid::Stage>(canvas_, [] { |
| 91 | /* no-op: ImGui host redraws every frame; see comment above */ |
| 92 | }); |
| 93 | if (stage->initialize(params_from(model_.at(i)))) { |
| 94 | by_name_.try_emplace(name, Entry{std::move(stage), rev}); |
| 95 | } else { |
| 96 | std::cerr << "[Error] failed to initialize Stage for buffer '" |
| 97 | << name << "'\n"; |
| 98 | } |
| 99 | } else if (it->second.revision != rev) { |
| 100 | // Re-plot: rebuild the Stage's GL buffer from the record's |
| 101 | // current bytes while preserving the Stage's camera/zoom, then |
| 102 | // record the new revision so this isn't repeated next sync(). |
| 103 | if (!it->second.stage->buffer_update(params_from(model_.at(i)))) { |
| 104 | std::cerr << "[Error] failed to update Stage for buffer '" |
| 105 | << name << "'\n"; |
| 106 | } |
| 107 | it->second.revision = rev; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // Drop Stages for buffers no longer present in the model. Erasing here |
| 112 | // destroys the Stage (and the span into its now-gone BufferRecord) |
| 113 | // before any dangling reference could be observed. |
| 114 | std::erase_if(by_name_, [&live_names](const auto& kv) { |
| 115 | return !live_names.contains(kv.first); |
| 116 | }); |
| 117 | } |
| 118 | |
| 119 | } // namespace oid::host |
nothing calls this directly
no test coverage detected