From 6cac284aff647fe3395ed939b7606c5a6e1de7f0 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 19 Oct 2020 20:43:44 -0600 Subject: [PATCH] Clear any properties already set when calling Particle::set_property_pool(). --- include/deal.II/particles/particle.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/deal.II/particles/particle.h b/include/deal.II/particles/particle.h index 81b3197827..20eefd3af9 100644 --- a/include/deal.II/particles/particle.h +++ b/include/deal.II/particles/particle.h @@ -334,6 +334,11 @@ namespace Particles * since the particle does not know about the properties, * we want to do it not at construction time. Another use for this * function is after particle transfer to a new process. + * + * If a particle already stores properties in a property pool, then + * these are released and the particle will not store any properties + * after this call (though new properties can be assigned to it using + * the set_properties() call). */ void set_property_pool(PropertyPool &property_pool); @@ -549,7 +554,15 @@ namespace Particles inline void Particle::set_property_pool(PropertyPool &new_property_pool) { + // If the particle currently has a reference to properties, then + // release those + if (property_pool != nullptr && properties != PropertyPool::invalid_handle) + property_pool->deallocate_properties_array(properties); + + // Then start from scratch, with no properties associated with the current + // particle property_pool = &new_property_pool; + properties = PropertyPool::invalid_handle; } -- 2.39.5