From 29e4725c53ab404e838e9ddf43c4eb2308e739ee Mon Sep 17 00:00:00 2001 From: Jan Schnathmeier <jschnathmeier@rompuy.informatik.rwth-aachen.de> Date: Fri, 29 May 2020 19:29:03 +0200 Subject: [PATCH] BUGFIX: (probably) fixed a small memory leak that would happen when rerolling triangulations too often. --- Embedding.cc | 30 ++++++++++++++++++++++++++++-- Embedding.hh | 1 + MetaMeshPlugin.cc | 10 +++++----- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Embedding.cc b/Embedding.cc index 6ed84f9..d654307 100644 --- a/Embedding.cc +++ b/Embedding.cc @@ -200,7 +200,19 @@ void Embedding::RandomTriangulation(TriMesh &base_mesh, PolyMesh &meta_mesh, dou while (!TriangulationPipeline(meta_mesh_points)) { meta_mesh_points.clear(); qDebug() << "Automatically remeshing"; + // TODO: There is a memory leak somewhere in here that shows when Triangulation has to + // be repeated many times because some Voronoi regions were of the wrong Euler characteristic. + // In those cases TriangulationPipeline returns false, and everything is repeated. + // Calling clear() here does not seem to deallocate all memory that should be + // deallocated. But inside the clear() function it looks like it deallocates all + // properties and also calls clean() afterwards. All the memory allocated at this point + // should be in the form of elements and properties of base_mesh_ and meta_mesh_. + // __Most likely__ this bug was due to not removing the new properties and doubly + // creating them when TriangulationPipeline() is called again, but I have no time left + // for extensive testing. IF some memory error crops up again when rerolling triangulations + // it is most likely here but I don't know what exactly causes it. meta_mesh_->clear(); + RemoveProperties(); if (rtype == RATIO) { for (auto vh : base_mesh_->vertices()) { if (dis0(gen) == 1) @@ -251,14 +263,28 @@ void Embedding::InitializeProperties() { base_mesh_->add_property(halfedge_weight_, "Pointer from base he to meta heh"); } +/*! + * \brief Embedding::RemoveProperties + */ +void Embedding::RemoveProperties() { + base_mesh_->remove_property(voronoiID_); + base_mesh_->remove_property(bsplithandle_); + base_mesh_->remove_property(bv_connection_); + meta_mesh_->remove_property(mv_connection_); + base_mesh_->remove_property(bhe_connection_); + meta_mesh_->remove_property(mhe_connection_); + base_mesh_->remove_property(bhe_border_); + meta_mesh_->remove_property(mhe_border_); + base_mesh_->remove_property(next_heh_); + base_mesh_->remove_property(halfedge_weight_); +} + /*! * \brief Embedding::CreateMetaMeshVertices * \param meta_mesh_points */ void Embedding::CreateMetaMeshVertices(std::vector<OpenMesh::VertexHandle> meta_mesh_points) { qDebug() << "Start appointing BaseMesh properties:"; - qDebug() << "is bv_connection_ valid? " << bv_connection_.is_valid(); - qDebug() << "is bsplithandle_ valid? " << bsplithandle_.is_valid(); for (auto bvh : base_mesh_->vertices()) { base_mesh_->property(bv_connection_, bvh) = OpenMesh::PolyConnectivity::InvalidVertexHandle; base_mesh_->property(bsplithandle_, bvh) = OpenMesh::PolyConnectivity::InvalidHalfedgeHandle; diff --git a/Embedding.hh b/Embedding.hh index 7b406d0..382bc08 100644 --- a/Embedding.hh +++ b/Embedding.hh @@ -89,6 +89,7 @@ private: bool TriangulationPipeline( std::vector<OpenMesh::VertexHandle> meta_mesh_points); void InitializeProperties(); + void RemoveProperties(); bool TriangulateMetaMesh(); void PreProcessEdges(); void ProcessHalfedge(OpenMesh::HalfedgeHandle mheh); diff --git a/MetaMeshPlugin.cc b/MetaMeshPlugin.cc index d197648..8351a7c 100644 --- a/MetaMeshPlugin.cc +++ b/MetaMeshPlugin.cc @@ -429,13 +429,13 @@ void MetaMeshPlugin::copyselection() { void MetaMeshPlugin::DummySlotFunction1() { using namespace PluginFunctions; for (auto bheh : embedding_->GetBaseMesh()->halfedges()) { - if (embedding_->GetMetaMesh()->is_valid_handle( - embedding_->GetBaseMesh()->property( - embedding_->bhe_connection_, bheh))) { - embedding_->GetBaseMesh()->status(bheh).set_selected(true); - } + embedding_->GetBaseMesh()->status(bheh).set_selected(false); + } + for (auto mheh : meta_mesh_->halfedges()) { + meta_mesh_->status(mheh).set_selected(false); } emit updatedObject(base_mesh_id_, UPDATE_SELECTION); + emit updatedObject(meta_mesh_id_, UPDATE_SELECTION); } /*! -- GitLab