diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-04-08 18:05:23 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-04-08 18:05:23 +0200 |
commit | 9cca30206a8de348bde4bddfa8ae10bd35ea8b66 (patch) | |
tree | d20df7e01a4ca4ef26b5c6cfb369b0d96c0598ca /editor/imgui-inspect.cpp | |
parent | 9d3d8c46af491b0aece27129f0a7ded247669960 (diff) |
editor: fix inspector use after free
Diffstat (limited to 'editor/imgui-inspect.cpp')
-rw-r--r-- | editor/imgui-inspect.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/editor/imgui-inspect.cpp b/editor/imgui-inspect.cpp index cb5b9ce7..a1adbba3 100644 --- a/editor/imgui-inspect.cpp +++ b/editor/imgui-inspect.cpp @@ -25,31 +25,37 @@ void app::draw_inspector() } const auto dpi = M->dpi_scale(); + auto& w = M->world(); for (auto i = inspectors.size()-1; i != -1uz; i--) { - auto [e, target] = inspectors[i]; - fm_debug_assert(e); - auto& s = *e; - chunk_coords ch = e->coord.chunk(); - local_coords pos = e->coord.local(); - auto z = e->coord.z(); + auto [id, target] = inspectors[i]; + auto e_ = w.find_entity(id); + if (!e_) + { + inspectors.erase(inspectors.begin() + ptrdiff_t(i)); + continue; + } + auto& e = *e_; + chunk_coords ch = e.coord.chunk(); + local_coords pos = e.coord.local(); + auto z = e.coord.z(); char buf[32]; - snformat(buf, "inspector-{:08x}"_cf, s.id); + snformat(buf, "inspector-{:08x}"_cf, e.id); auto b1 = push_id(buf); ImGui::SetNextWindowSize({300*dpi[0], 0}); - auto name = loader.strip_prefix(s.atlas->name()); + auto name = loader.strip_prefix(e.atlas->name()); if (z == 0) snformat(buf, "{} ({}x{} -> {}x{})"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y); else snformat(buf, "{} ({}x{}:{} -> {}x{})"_cf, name, ch.x, ch.y, (int)z, (int)pos.x, (int)pos.y); bool is_open = true; - if (s.type() == entity_type::scenery) + if (e.type() == entity_type::scenery) { - auto& s2 = static_cast<scenery&>(s); + auto& s2 = static_cast<scenery&>(e); if (auto b2 = begin_window(buf, &is_open)) { bool ret = entities::inspect_type(s2); |