From 379c619cfbe6ec74ab616f897fc9157e595b2997 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Tue, 7 Mar 2017 22:55:06 +0000
Subject: [PATCH] Fixed bug in runner_do_end_force().

---
 src/runner.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/runner.c b/src/runner.c
index 521914bfde..4c499af218 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -1350,7 +1350,13 @@ void runner_do_end_force(struct runner *r, struct cell *c, int timer) {
 
       /* Get a handle on the part. */
       struct part *restrict p = &parts[k];
-      if (part_is_active(p, e)) hydro_end_force(p);
+
+      if (part_is_active(p, e)) {
+	
+	/* First, finish the force loop */
+	hydro_end_force(p);
+        if (p->gpart != NULL) gravity_end_force(p->gpart, const_G);
+      }
     }
 
     /* Loop over the g-particles in this cell. */
@@ -1358,7 +1364,12 @@ void runner_do_end_force(struct runner *r, struct cell *c, int timer) {
 
       /* Get a handle on the gpart. */
       struct gpart *restrict gp = &gparts[k];
-      if (gpart_is_active(gp, e)) gravity_end_force(gp, const_G);
+
+      if (gp->type == swift_type_dark_matter) {
+
+	if (gpart_is_active(gp, e)) gravity_end_force(gp, const_G);
+
+      }
 
 #ifdef SWIFT_DEBUG_CHECKS
       if (e->policy & engine_policy_self_gravity) {
@@ -1377,7 +1388,12 @@ void runner_do_end_force(struct runner *r, struct cell *c, int timer) {
 
       /* Get a handle on the spart. */
       struct spart *restrict sp = &sparts[k];
-      if (spart_is_active(sp, e)) star_end_force(sp);
+      if (spart_is_active(sp, e)) {
+
+	/* First, finish the force loop */
+	star_end_force(sp);
+        gravity_end_force(sp->gpart, const_G);
+      }
     }
   }
 
-- 
GitLab