Skip to content

Commit a6cd141

Browse files
committed
fix #549, survival() callback move did not update has_null_haplosomes_
1 parent 06ddc76 commit a6cd141

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ development head (in the master branch):
1717
add a (numeric)sign(numeric x) function that returns the sign (-1, 0, 1) of each element
1818
calcFST() with a windowed range (start/end) would error; was missing a unit test (#548)
1919
calcSFS() with an integer (non-NULL) binCount would error in multi-chromosome models if mutations from multiple chromosomes (or NULL) were given
20+
survival() callback that moves individuals did not correctly update has_null_haplosomes_, leading to a crash or a DEBUG raise (#549)
2021

2122

2223
version 5.0 (Eidos version 4.0):

core/population.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ void Population::ResolveSurvivalPhaseMovement(void)
477477
}
478478

479479
// loop through subpops and append individuals that are arriving; we do this using Subpopulation::MergeReproductionOffspring()
480+
int haplosome_count_per_individual = species_.HaplosomeCountPerIndividual();
481+
480482
for (std::pair<const slim_objectid_t,Subpopulation*> &subpop_pair : subpops_)
481483
{
482484
Subpopulation *subpop = subpop_pair.second;
@@ -490,6 +492,23 @@ void Population::ResolveSurvivalPhaseMovement(void)
490492
++subpop->gui_migrants_[individual->subpopulation_->subpopulation_id_];
491493
#endif
492494

495+
// has_null_haplosomes_ needs to reflect the presence of null haplosomes
496+
if (!subpop->has_null_haplosomes_ && individual->subpopulation_->has_null_haplosomes_)
497+
{
498+
Haplosome **haplosomes = individual->haplosomes_;
499+
500+
for (int haplosome_index = 0; haplosome_index < haplosome_count_per_individual; haplosome_index++)
501+
{
502+
Haplosome *haplosome = haplosomes[haplosome_index];
503+
504+
if (haplosome->IsNull())
505+
{
506+
subpop->has_null_haplosomes_ = true;
507+
break;
508+
}
509+
}
510+
}
511+
493512
individual->subpopulation_ = subpop;
494513
individual->migrant_ = true;
495514
}

core/subpopulation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8852,7 +8852,10 @@ EidosValue_SP Subpopulation::ExecuteMethod_takeMigrants(EidosGlobalStringID p_me
88528852
Haplosome *haplosome = haplosomes[haplosome_index];
88538853

88548854
if (haplosome->IsNull())
8855+
{
88558856
has_null_haplosomes_ = true;
8857+
break;
8858+
}
88568859
}
88578860
}
88588861

core/subpopulation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Subpopulation : public EidosDictionaryUnretained
120120
std::vector<Individual *> &individuals_junkyard_; // NOT OWNED: individuals get put here when we're done with them, so we can reuse them quickly
121121

122122
int haplosome_count_per_individual_; // inherits its value from species_.haplosome_count_per_individual_
123-
bool has_null_haplosomes_ = false; // inherits its value from species_.chromosomes_use_null_haplosomes_ but can additionally be false; use CouldContainNullHaplosomes() to check this flag
123+
bool has_null_haplosomes_ = false; // inherits its value from species_.chromosomes_use_null_haplosomes_ but can additionally be true; use CouldContainNullHaplosomes() to check this flag
124124

125125
slim_popsize_t parent_subpop_size_; // parental subpopulation size
126126
slim_popsize_t parent_first_male_index_ = INT_MAX; // the index of the first male in the parental Haplosome vector (NOT premultiplied by 2!); equal to the number of females

0 commit comments

Comments
 (0)