From: Wolfgang Bangerth Date: Tue, 20 Oct 2020 02:43:44 +0000 (-0600) Subject: Clear any properties already set when calling Particle::set_property_pool(). X-Git-Tag: v9.3.0-rc1~997^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6cac284aff647fe3395ed939b7606c5a6e1de7f0;p=dealii.git Clear any properties already set when calling Particle::set_property_pool(). --- 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; }