Skip to content

Commit a04ffa2

Browse files
committed
Only saving cells data when there are cells
1 parent 69a23db commit a04ffa2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

modules/PhysiCell_MultiCellDS.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void add_PhysiCell_cells_to_open_xml_pugi_v2( pugi::xml_document& xml_dom, std::
199199
// get number of cell types
200200
static int n = cell_definition_indices_by_name.size(); // number_of_cell_types
201201
// get number of death models
202-
static int nd = (*all_cells)[0]->phenotype.death.rates.size(); //
202+
static int nd = all_cells->size() > 0 ? (*all_cells)[0]->phenotype.death.rates.size() : 0; //
203203
// get number of custom data
204204
static int nc = 0; //
205205
static int nc_scalar = 0;
@@ -587,7 +587,8 @@ void add_PhysiCell_cells_to_open_xml_pugi_v2( pugi::xml_document& xml_dom, std::
587587
"damage_repair_rate" , "1/min" , 1 );
588588

589589
// custom
590-
for( int j=0 ; j < (*all_cells)[0]->custom_data.variables.size(); j++ )
590+
int nvariables = all_cells->size() > 0 ? (*all_cells)[0]->custom_data.variables.size() : 0;
591+
for( int j=0 ; j < nvariables; j++ )
591592
{
592593
name = (*all_cells)[0]->custom_data.variables[j].name;
593594
units = (*all_cells)[0]->custom_data.variables[j].units;
@@ -596,7 +597,8 @@ void add_PhysiCell_cells_to_open_xml_pugi_v2( pugi::xml_document& xml_dom, std::
596597
}
597598

598599
// custom vector variables
599-
for( int j=0 ; j < (*all_cells)[0]->custom_data.vector_variables.size(); j++ )
600+
int nvectorvariables = all_cells->size() ? (*all_cells)[0]->custom_data.vector_variables.size() : 0;
601+
for( int j=0 ; j < nvectorvariables; j++ )
600602
{
601603
name = (*all_cells)[0]->custom_data.vector_variables[j].name;
602604
units = (*all_cells)[0]->custom_data.vector_variables[j].units;
@@ -995,11 +997,13 @@ void add_PhysiCell_cells_to_open_xml_pugi_v2( pugi::xml_document& xml_dom, std::
995997

996998
// custom
997999
// custom scalar variables
998-
for( int j=0 ; j < (*all_cells)[0]->custom_data.variables.size(); j++ )
1000+
int nvariables = all_cells->size() > 0 ? (*all_cells)[0]->custom_data.variables.size() : 0;
1001+
for( int j=0 ; j < nvariables; j++ )
9991002
{ std::fwrite( &( pCell->custom_data.variables[j].value ) , sizeof(double) , 1 , fp ); }
10001003

10011004
// custom vector variables
1002-
for( int j=0 ; j < (*all_cells)[0]->custom_data.vector_variables.size(); j++ )
1005+
int nvectorvariables = all_cells->size() > 0 ? (*all_cells)[0]->custom_data.vector_variables.size() : 0;
1006+
for( int j=0 ; j < nvectorvariables; j++ )
10031007
{
10041008
int size_temp = pCell->custom_data.vector_variables[j].value.size();
10051009
std::fwrite( pCell->custom_data.vector_variables[j].value.data() , sizeof(double) , size_temp , fp );

0 commit comments

Comments
 (0)