diff --git a/src/engine.c b/src/engine.c
index f4841ee7c181c0b39d9ac2b12d271bf355adc646..f97cb7a72f53963b479cbe20363084eee83402e8 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -2321,6 +2321,10 @@ void engine_make_self_gravity_tasks(struct engine *e) {
   if (periodic)
     for (int i = 0; i < s->nr_cells; ++i) {
       const struct cell *c = &s->cells_top[i];
+      /* Skip empty cells */
+      if (c->gcount == 0) continue;
+
+      /* Did we correctly attach the FFT task ghosts? */
       if (c->nodeID == engine_rank &&
           (c->grav_ghost_in == NULL || c->grav_ghost_out == NULL))
         error("Invalid gravity_ghost for local cell");
diff --git a/src/runner_doiact_grav.h b/src/runner_doiact_grav.h
index 384e7fa8429f6675846e10646fb873e8377b070a..2f8f535ff7bc2d1b6562d4ce4ca93beba2350312 100644
--- a/src/runner_doiact_grav.h
+++ b/src/runner_doiact_grav.h
@@ -1179,6 +1179,9 @@ void runner_do_grav_long_range(struct runner *r, struct cell *ci, int timer) {
     /* Avoid self contributions */
     if (ci == cj) continue;
 
+    /* Skip empty cells */
+    if (cj->gcount == 0) continue;
+
     /* Get the distance between the CoMs at the last rebuild*/
     double dx_r = CoM_rebuild_i[0] - multi_j->CoM_rebuild[0];
     double dy_r = CoM_rebuild_i[1] - multi_j->CoM_rebuild[1];