From 7a29b2cb54e6aedd0936817d2a5b62cfe0716c68 Mon Sep 17 00:00:00 2001 From: Charles Ofria Date: Thu, 5 Apr 2018 22:44:31 -0400 Subject: [PATCH] Make sure offspring organisms are deleted if DoBirth fails. --- source/Evolve/World.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/Evolve/World.h b/source/Evolve/World.h index 56f320a5d3..a590660f66 100644 --- a/source/Evolve/World.h +++ b/source/Evolve/World.h @@ -18,6 +18,7 @@ * facilitate demes, pools, islands, etc. * @todo We should be able to have any number of systematics managers, based on various type_trait * information a that we want to track. + * @todo Add a signal for DoBirth() for when a birth fails. */ #ifndef EMP_EVO_WORLD_H @@ -1024,7 +1025,13 @@ namespace emp { Ptr new_org = NewPtr(mem); offspring_ready_sig.Trigger(*new_org); const OrgPosition pos = fun_add_birth(new_org, parent_pos); - if (pos.IsActive()) org_placement_sig.Trigger(pos.GetIndex()); + if (pos.IsActive()) { + // If organism was placed right into the active population, trigger placement signal. + org_placement_sig.Trigger(pos.GetIndex()); + } else if (!pos.IsValid()) { + // Organism failed to be placed in the population. Delete it. + new_org.Delete(); + } // SetupOrg(*new_org, &callbacks, pos); return pos; }