]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix bug with un-initialized field 12913/head
authorMartin Kronbichler <martin.kronbichler@it.uu.se>
Tue, 9 Nov 2021 09:00:49 +0000 (10:00 +0100)
committerMartin Kronbichler <martin.kronbichler@it.uu.se>
Tue, 9 Nov 2021 09:00:49 +0000 (10:00 +0100)
include/deal.II/particles/particle_handler.h
source/particles/particle_handler.cc

index 66f95133411785b385c9a70205bac893c774cc8d..e5753282cf7e8aad86d82c8d8c9c8975adbefafc 100644 (file)
@@ -897,8 +897,7 @@ namespace Particles
      * container to check for valid states.
      */
     void
-    reset_particle_container(const Triangulation<dim, spacedim> *triangulation,
-                             particle_container &                particles);
+    reset_particle_container(particle_container &particles);
 
     /**
      * Address of the triangulation to work on.
index 57e17a8002e58686679c12a51d5bf36ad1a2859d..bcfa91ea9403f080a923c4a614c37ed198286683 100644 (file)
@@ -68,7 +68,7 @@ namespace Particles
     , handle(numbers::invalid_unsigned_int)
     , tria_listeners()
   {
-    reset_particle_container(nullptr, particles);
+    reset_particle_container(particles);
   }
 
 
@@ -95,7 +95,7 @@ namespace Particles
                                                           mapping))
     , tria_listeners()
   {
-    reset_particle_container(&triangulation, particles);
+    reset_particle_container(particles);
     connect_to_triangulation_signals();
   }
 
@@ -124,7 +124,7 @@ namespace Particles
     triangulation = &new_triangulation;
     mapping       = &new_mapping;
 
-    reset_particle_container(&new_triangulation, particles);
+    reset_particle_container(particles);
 
     // Create the memory pool that will store all particle properties
     property_pool = std::make_unique<PropertyPool<dim, spacedim>>(n_properties);
@@ -209,14 +209,10 @@ namespace Particles
           property_pool->deregister_particle(particle);
 
     cells_to_particle_cache.clear();
+    reset_particle_container(particles);
     if (triangulation != nullptr)
-      {
-        reset_particle_container(&*triangulation, particles);
-        cells_to_particle_cache.resize(triangulation->n_active_cells(),
-                                       particles.end());
-      }
-    else
-      reset_particle_container(nullptr, particles);
+      cells_to_particle_cache.resize(triangulation->n_active_cells(),
+                                     particles.end());
 
     // the particle properties have already been deleted by their destructor,
     // but the memory is still allocated. Return the memory as well.
@@ -228,14 +224,21 @@ namespace Particles
   template <int dim, int spacedim>
   void
   ParticleHandler<dim, spacedim>::reset_particle_container(
-    const Triangulation<dim, spacedim> *triangulation,
-    particle_container &                given_particles)
+    particle_container &given_particles)
   {
+    // Make sure to set a valid past-the-end iterator also in case we have no
+    // triangulation
+    const typename Triangulation<dim, spacedim>::cell_iterator
+      past_the_end_iterator =
+        triangulation != nullptr ?
+          triangulation->end() :
+          typename Triangulation<dim, spacedim>::cell_iterator(nullptr, -1, -1);
+
     given_particles.clear();
     for (unsigned int i = 0; i < 3; ++i)
       given_particles.emplace_back(
         std::vector<typename PropertyPool<dim, spacedim>::Handle>(),
-        triangulation->end());
+        past_the_end_iterator);
 
     // Set the end of owned particles to the middle of the three elements
     const_cast<typename particle_container::iterator &>(owned_particles_end) =
@@ -275,7 +278,7 @@ namespace Particles
         // into a new one (keeping alive the possibly large vectors with
         // particles on cells) into a new container.
         particle_container sorted_particles;
-        reset_particle_container(&*triangulation, sorted_particles);
+        reset_particle_container(sorted_particles);
 
         // iterate over cells and insert the entries in the new order
         for (const auto &cell : triangulation->active_cell_iterators())

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.