From 28c0ebf09653ff1253f889704fa1e7d80591d1bb Mon Sep 17 00:00:00 2001 From: Luke Street Date: Thu, 27 May 2021 08:25:55 -0400 Subject: [PATCH] Fix double free; add credits to About --- Runtime/ImGuiConsole.cpp | 21 +++++++++++++++++++-- Runtime/ImGuiEntitySupport.cpp | 7 ++++--- imgui/ImGuiEngine.cpp | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index f8bf67afe..965175246 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -178,7 +178,9 @@ void ImGuiConsole::BeginEntityRow(const ImGuiEntityEntry& entry) { auto text = fmt::format(FMT_STRING("{:x}"), entry.uid.Value()); ImGui::Selectable(text.c_str(), &entry.ent->m_debugSelected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap); - entry.ent->m_debugHovered = ImGui::IsItemHovered(); + if (ImGui::IsItemHovered()) { + entry.ent->m_debugHovered = true; + } if (ImGui::BeginPopupContextItem(text.c_str())) { ImGui::PopStyleColor(); @@ -313,7 +315,7 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) { bool ImGuiConsole::ShowEntityInfoWindow(TUniqueId uid) { bool open = true; ImGuiEntityEntry& entry = ImGuiConsole::entities[uid.Value()]; - auto name = fmt::format(FMT_STRING("{}##{:x}"), !entry.name.empty() ? entry.name : "Entity", uid.Value()); + auto name = fmt::format(FMT_STRING("{}##{:x}"), !entry.name.empty() ? entry.name : entry.type, uid.Value()); if (ImGui::Begin(name.c_str(), &open, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::PushID(uid.Value()); entry.ent->ImGuiInspect(); @@ -338,6 +340,11 @@ void ImGuiConsole::ShowAboutWindow() { ImGuiTextCenter(METAFORCE_WC_DESCRIBE); const ImVec2& padding = ImGui::GetStyle().WindowPadding; ImGui::Dummy(padding); + ImGuiTextCenter("2015-2021"); + ImGuiTextCenter("Phillip Stephens (Antidote)"); + ImGuiTextCenter("Jack Andersen (jackoalan)"); + ImGuiTextCenter("Luke Street (encounter)"); + ImGuiTextCenter("Metaforce contributors"); ImGui::Dummy(padding); ImGui::Separator(); if (ImGui::BeginTable("Version Info", 2, ImGuiTableFlags_BordersInnerV)) { @@ -362,6 +369,13 @@ void ImGuiConsole::ShowAboutWindow() { if (ImGui::TableNextColumn()) { ImGui::TextUnformatted(METAFORCE_WC_DATE); } + ImGui::TableNextRow(); + if (ImGui::TableNextColumn()) { + ImGui::TextUnformatted("Build name"); + } + if (ImGui::TableNextColumn()) { + ImGui::TextUnformatted(METAFORCE_DLPACKAGE); + } ImGui::EndTable(); } } @@ -623,6 +637,9 @@ void ImGuiConsole::PostUpdate() { inspectingEntities.erase(item.uid); item.uid = kInvalidUniqueId; item.ent = nullptr; // for safety + } else { + // Clear debug hovered + ent->m_debugHovered = false; } } } else { diff --git a/Runtime/ImGuiEntitySupport.cpp b/Runtime/ImGuiEntitySupport.cpp index e96fc79d4..900f79f8d 100644 --- a/Runtime/ImGuiEntitySupport.cpp +++ b/Runtime/ImGuiEntitySupport.cpp @@ -227,7 +227,7 @@ void CEntity::ImGuiInspect() { ImGui::EndTable(); } } - if (m_incomingConnections && ImGui::CollapsingHeader("Incoming Connections")) { + if (m_incomingConnections != nullptr && ImGui::CollapsingHeader("Incoming Connections")) { if (ImGui::BeginTable("Incoming Connections", 6, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV)) { ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed, 0, 'id'); @@ -235,10 +235,11 @@ void CEntity::ImGuiInspect() { ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 0, 'name'); ImGui::TableSetupColumn("State", ImGuiTableColumnFlags_WidthFixed, 0, 'stat'); ImGui::TableSetupColumn("Message", ImGuiTableColumnFlags_WidthFixed, 0, 'msg'); - ImGui::TableSetupColumn("", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed | + ImGuiTableColumnFlags_NoResize); ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableHeadersRow(); - for (const auto& item : (*m_incomingConnections)) { + for (const auto& item : *m_incomingConnections) { const auto uid = g_StateManager->GetIdForScript(item.x8_objId); if (uid == kInvalidUniqueId) { continue; diff --git a/imgui/ImGuiEngine.cpp b/imgui/ImGuiEngine.cpp index 768ddaeaf..90bfbc5a5 100644 --- a/imgui/ImGuiEngine.cpp +++ b/imgui/ImGuiEngine.cpp @@ -108,6 +108,7 @@ void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* w snprintf(fontConfig.Name, sizeof(fontConfig.Name), "Noto Mono Regular, %dpx", static_cast(fontConfig.SizePixels)); fontNormal = io.Fonts->AddFont(&fontConfig); + fontConfig.FontDataOwnedByAtlas = false; // first one took ownership fontConfig.SizePixels = std::floor(24.f * scale); snprintf(fontConfig.Name, sizeof(fontConfig.Name), "Noto Mono Regular, %dpx", static_cast(fontConfig.SizePixels));