summaryrefslogtreecommitdiffhomepage
path: root/editor/imgui.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-08 18:05:23 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-08 18:05:23 +0200
commit9cca30206a8de348bde4bddfa8ae10bd35ea8b66 (patch)
treed20df7e01a4ca4ef26b5c6cfb369b0d96c0598ca /editor/imgui.cpp
parent9d3d8c46af491b0aece27129f0a7ded247669960 (diff)
editor: fix inspector use after free
Diffstat (limited to 'editor/imgui.cpp')
-rw-r--r--editor/imgui.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 32b85cb8..2396f1bb 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -147,21 +147,25 @@ bool app::check_inspector_exists(const popup_target& p)
void app::do_popup_menu()
{
- const auto [sc, target] = _popup_target;
- if (target == popup_target_type::none || sc == nullptr)
+ const auto [id, target] = _popup_target;
+ auto& w = M->world();
+ auto e_ = w.find_entity(id);
+
+ if (target == popup_target_type::none || !e_)
{
_popup_target = {};
_pending_popup = {};
return;
}
+ auto& e = *e_;
+
auto b0 = push_id(SCENERY_POPUP_NAME);
//if (_popup_target.target != popup_target_type::scenery) {...}
if (_pending_popup)
{
_pending_popup = false;
- fm_assert(target != popup_target_type::none && sc != nullptr);
//if (type != popup_target_type::scenery) {...}
ImGui::OpenPopup(SCENERY_POPUP_NAME.data());
}
@@ -169,18 +173,18 @@ void app::do_popup_menu()
if (auto b1 = begin_popup(SCENERY_POPUP_NAME))
{
ImGui::SeparatorText("Setup");
- const auto i = sc->index();
- if (ImGui::MenuItem("Activate", nullptr, false, sc->can_activate(i)))
- sc->activate(i);
+ const auto i = e.index();
+ if (ImGui::MenuItem("Activate", nullptr, false, e.can_activate(i)))
+ e.activate(i);
if (bool b_ins = !check_inspector_exists(_popup_target);
ImGui::MenuItem("Inspect", nullptr, !b_ins, b_ins))
inspectors.push_back(std::exchange(_popup_target, {}));
ImGui::SeparatorText("Modify");
- if (auto next_rot = sc->atlas->next_rotation_from(sc->r);
- ImGui::MenuItem("Rotate", nullptr, false, next_rot != sc->r && sc->can_rotate(next_rot)))
- sc->rotate(i, next_rot);
+ if (auto next_rot = e.atlas->next_rotation_from(e.r);
+ ImGui::MenuItem("Rotate", nullptr, false, next_rot != e.r && e.can_rotate(next_rot)))
+ e.rotate(i, next_rot);
if (ImGui::MenuItem("Delete", nullptr, false))
- sc->chunk().remove_entity(sc->index());
+ e.chunk().remove_entity(e.index());
}
}