From 72339476bb9d252c2752c662d9153dd81753991e Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Feb 2023 14:46:36 +0100 Subject: Fixed ID push before checking validity --- kurator/src/Battle.cpp | 2 +- kurator/src/inspect.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index b0719ea..fe3c37b 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -103,12 +103,12 @@ Battle::update() blink_crosses(ctx); animate_lines(ctx); balance.update(ctx.registry); + inspect.show(); ImGui::SetNextWindowPos({GetScreenWidth()/2.0f, GetScreenHeight()-100.0f}, ImGuiCond_Once, {0.5f, 0.5f}); ImGui::SetNextWindowSize({240.0f, 0.0f}, ImGuiCond_Once); if (ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_NoFocusOnAppearing)) time_controls("TimeControls", ctx.clock.time_factor); ImGui::End(); - inspect.show(); } diff --git a/kurator/src/inspect.cpp b/kurator/src/inspect.cpp index 4795068..062630c 100644 --- a/kurator/src/inspect.cpp +++ b/kurator/src/inspect.cpp @@ -43,11 +43,11 @@ InspectionWindow::show() if (ImGui::Begin("Inspect", &open)) { auto it = selected.begin(); while (it != selected.end()) { - ImGui::PushID(it - selected.begin()); if (!it->valid()) { it = selected.erase(it); continue; } + ImGui::PushID(it - selected.begin()); inspect(*it); inspect(*it); inspect(*it); @@ -90,6 +90,8 @@ void InspectionWindow::deselect() { for (auto&& entity_ : selected) { + if (!entity_.valid()) + continue; if (entity_.all_of()) entity_.get().selected = false; if (entity_.all_of()) @@ -154,12 +156,13 @@ inspect(entt::handle&, TurretVisuals& visuals) static Color OPTIMAL {0x88, 0x22, 0x22, 0xff}; static Color EFFECTIVE {0x77, 0x50, 0x22, 0xff}; + void draw_turret_visuals(const sim::State& ctx) { const auto helpers = ctx.registry.view(); for (const auto& [entity, visuals, type, turret] : helpers.each()) { - if (!visuals.visible) + if (!visuals.visible || !ctx.registry.valid(turret.owner)) continue; const auto& transform = ctx.registry.get(turret.owner); const auto center = ctx.camera.to_screen(transform.position); -- cgit v1.1