diff --git a/core/PhysiCell_cell.cpp b/core/PhysiCell_cell.cpp index a14c70b99..e787bb717 100644 --- a/core/PhysiCell_cell.cpp +++ b/core/PhysiCell_cell.cpp @@ -1207,6 +1207,9 @@ void delete_cell( int index ) // released internalized substrates (as of 1.5.x releases) pDeleteMe->release_internalized_substrates(); + // new Dec 2, 2025 + pDeleteMe->remove_self_from_attackers(); + // performance goal: don't delete in the middle -- very expensive reallocation // alternative: copy last element to index position, then shrink vector by 1 at the end O(constant) @@ -3401,6 +3404,23 @@ void Cell::remove_self_from_all_neighbors( void ) else { /* future error message */ } } + + // This is a bit of a ugly hack, we need to find the origin of that bug + for ( int i = 0; i < all_cells->size(); i++ ) + { + Cell* pC = (*all_cells)[i]; + if (pC != this) + { + auto SearchResult = std::find( + pC->state.neighbors.begin(),pC->state.neighbors.end(),this ); + if ( SearchResult != pC->state.neighbors.end() ) + { + std::cout << "Cell " << pC->ID << " still has cell " << this->ID << " as a neighbor!" << std::endl; + pC->state.neighbors.erase( SearchResult ); + } + } + } + return; } @@ -3430,9 +3450,38 @@ void Cell::remove_all_spring_attachments( void ) // clear my list state.spring_attachments.clear(); } + + // This is a bit of a ugly hack, we need to find the origin of that bug + for ( int i = 0; i < all_cells->size(); i++ ) + { + Cell* pC = (*all_cells)[i]; + if (pC != this) + { + auto SearchResult = std::find( + pC->state.spring_attachments.begin(),pC->state.spring_attachments.end(),this ); + if ( SearchResult != pC->state.spring_attachments.end() ) + { + std::cout << "Cell " << pC->ID << " still has cell " << this->ID << " as a spring attachment!" << std::endl; + pC->state.spring_attachments.erase( SearchResult ); + } + + } + } + return; } +void Cell::remove_self_from_attackers( void ) +{ + #pragma omp parallel for + for (int j=0; j < all_cells->size(); j++) + { + Cell* pC = (*all_cells)[j]; + if (( pC != this) && pC->phenotype.cell_interactions.pAttackTarget == this) { + pC->phenotype.cell_interactions.pAttackTarget = NULL; + } + } +} void attach_cells( Cell* pCell_1, Cell* pCell_2 ) { diff --git a/core/PhysiCell_cell.h b/core/PhysiCell_cell.h index 5b7c52d96..4de5fcebe 100644 --- a/core/PhysiCell_cell.h +++ b/core/PhysiCell_cell.h @@ -238,6 +238,7 @@ class Cell : public Basic_Agent void attach_cell_as_spring( Cell* pAddMe ); // done void detach_cell_as_spring( Cell* pRemoveMe ); // done void remove_all_spring_attachments( void ); // done + void remove_self_from_attackers( void ); // I want to eventually deprecate this, by ensuring that // critical BioFVM and PhysiCell data elements are synced when they are needed