From: Martin Kronbichler Date: Tue, 9 Nov 2021 09:00:49 +0000 (+0100) Subject: Fix bug with un-initialized field X-Git-Tag: v9.4.0-rc1~849^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efb9b4a7c8cfd62ea6066d64c06d0127242e9860;p=dealii.git Fix bug with un-initialized field --- diff --git a/include/deal.II/particles/particle_handler.h b/include/deal.II/particles/particle_handler.h index 66f9513341..e5753282cf 100644 --- a/include/deal.II/particles/particle_handler.h +++ b/include/deal.II/particles/particle_handler.h @@ -897,8 +897,7 @@ namespace Particles * container to check for valid states. */ void - reset_particle_container(const Triangulation *triangulation, - particle_container & particles); + reset_particle_container(particle_container &particles); /** * Address of the triangulation to work on. diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 57e17a8002..bcfa91ea94 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -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>(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 void ParticleHandler::reset_particle_container( - const Triangulation *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::cell_iterator + past_the_end_iterator = + triangulation != nullptr ? + triangulation->end() : + typename Triangulation::cell_iterator(nullptr, -1, -1); + given_particles.clear(); for (unsigned int i = 0; i < 3; ++i) given_particles.emplace_back( std::vector::Handle>(), - triangulation->end()); + past_the_end_iterator); // Set the end of owned particles to the middle of the three elements const_cast(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())