From 31aed3ebca90cf065c3cb28acef99056fcd00842 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Sun, 28 Jul 2019 22:54:39 +0100 Subject: [PATCH] When removing an spart or a bpart, update the counters accordingly. --- src/cell.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/cell.c b/src/cell.c index 6ca4ca28d6..f4903f024b 100644 --- a/src/cell.c +++ b/src/cell.c @@ -5398,12 +5398,15 @@ void cell_remove_spart(const struct engine *e, struct cell *c, sp->gpart->type = swift_type_dark_matter; } - /* Un-link the spart */ - sp->gpart = NULL; - /* Update the space-wide counters */ const size_t one = 1; atomic_add(&e->s->nr_inhibited_sparts, one); + if (sp->gpart) { + atomic_add(&e->s->nr_inhibited_gparts, one); + } + + /* Un-link the spart */ + sp->gpart = NULL; } /** @@ -5434,12 +5437,15 @@ void cell_remove_bpart(const struct engine *e, struct cell *c, bp->gpart->type = swift_type_dark_matter; } - /* Un-link the bpart */ - bp->gpart = NULL; - /* Update the space-wide counters */ const size_t one = 1; atomic_add(&e->s->nr_inhibited_bparts, one); + if (bp->gpart) { + atomic_add(&e->s->nr_inhibited_gparts, one); + } + + /* Un-link the bpart */ + bp->gpart = NULL; } /** -- GitLab