Skip to content

Commit 7a29b2c

Browse files
committed
Make sure offspring organisms are deleted if DoBirth fails.
1 parent 6e6a4af commit 7a29b2c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

source/Evolve/World.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* facilitate demes, pools, islands, etc.
1919
* @todo We should be able to have any number of systematics managers, based on various type_trait
2020
* information a that we want to track.
21+
* @todo Add a signal for DoBirth() for when a birth fails.
2122
*/
2223

2324
#ifndef EMP_EVO_WORLD_H
@@ -1024,7 +1025,13 @@ namespace emp {
10241025
Ptr<ORG> new_org = NewPtr<ORG>(mem);
10251026
offspring_ready_sig.Trigger(*new_org);
10261027
const OrgPosition pos = fun_add_birth(new_org, parent_pos);
1027-
if (pos.IsActive()) org_placement_sig.Trigger(pos.GetIndex());
1028+
if (pos.IsActive()) {
1029+
// If organism was placed right into the active population, trigger placement signal.
1030+
org_placement_sig.Trigger(pos.GetIndex());
1031+
} else if (!pos.IsValid()) {
1032+
// Organism failed to be placed in the population. Delete it.
1033+
new_org.Delete();
1034+
}
10281035
// SetupOrg(*new_org, &callbacks, pos);
10291036
return pos;
10301037
}

0 commit comments

Comments
 (0)