1
0
mirror of synced 2024-11-28 01:20:51 +01:00

impr: Get rid of some manual memory management

This commit is contained in:
WerWolv 2023-08-25 23:54:39 +02:00
parent e487fd7450
commit 6e81ce152e
4 changed files with 10 additions and 11 deletions

View File

@ -115,7 +115,7 @@ namespace hex::prv {
[[nodiscard]] Overlay *newOverlay();
void deleteOverlay(Overlay *overlay);
[[nodiscard]] const std::list<Overlay *> &getOverlays();
[[nodiscard]] const std::list<std::unique_ptr<Overlay>> &getOverlays();
[[nodiscard]] size_t getPageSize() const;
void setPageSize(size_t pageSize);
@ -190,7 +190,7 @@ namespace hex::prv {
std::list<std::map<u64, u8>> m_patches;
decltype(m_patches)::iterator m_currPatches;
std::list<Overlay *> m_overlays;
std::list<std::unique_ptr<Overlay>> m_overlays;
u32 m_id;

View File

@ -26,8 +26,6 @@ namespace hex::prv {
}
Provider::~Provider() {
for (auto overlay : this->m_overlays)
delete overlay;
this->m_overlays.clear();
}
@ -163,15 +161,16 @@ namespace hex::prv {
Overlay *Provider::newOverlay() {
return this->m_overlays.emplace_back(new Overlay());
return this->m_overlays.emplace_back().get();
}
void Provider::deleteOverlay(Overlay *overlay) {
this->m_overlays.remove(overlay);
delete overlay;
this->m_overlays.remove_if([overlay](const auto &item) {
return item.get() == overlay;
});
}
const std::list<Overlay *> &Provider::getOverlays() {
const std::list<std::unique_ptr<Overlay>> &Provider::getOverlays() {
return this->m_overlays;
}

View File

@ -66,6 +66,8 @@ namespace hex {
bool m_hadEvent = false;
bool m_frameRateTemporarilyUnlocked = false;
double m_frameRateUnlockTime = 0;
ImGui::ImHexCustomData m_imguiCustomData;
};
}

View File

@ -1034,7 +1034,7 @@ namespace hex {
ImNodes::GetIO().LinkDetachWithModifierClick.Modifier = &always;
}
io.UserData = new ImGui::ImHexCustomData();
io.UserData = &this->m_imguiCustomData;
auto scale = ImHexApi::System::getGlobalScale();
style.ScaleAllSizes(scale);
@ -1128,8 +1128,6 @@ namespace hex {
}
void Window::exitImGui() {
delete static_cast<ImGui::ImHexCustomData *>(ImGui::GetIO().UserData);
ImGui::SaveIniSettingsToDisk(wolv::util::toUTF8String(s_imguiSettingsPath).c_str());
ImGui_ImplOpenGL3_Shutdown();