]> git.itanic.dy.fi Git - sdl-planets/commitdiff
merge_planets: Remove planet from linked lists before merging
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 20 Jul 2011 12:47:55 +0000 (15:47 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 20 Jul 2011 12:47:55 +0000 (15:47 +0300)
The planet needs to be remove from all linked lists before they are
being merged together. If merging takes place while both nodes are in
the same quad tree, the tree logic might collapse due to two nodes
sharing the same identical coordinates.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
planet.c

index 2c7d1435ff09fe8df676735e29f4ba2c3fe445d5..c6d8aeef956ad21adf3da8cb94b90ee64e68016f 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -266,11 +266,11 @@ static struct planet *_merge_planets(struct planet *a, struct planet *b)
 struct planet *merge_planets(struct planet *a, struct planet *b)
 {
        struct quadtree *p;
-       _merge_planets(a, b);
 
        list_del(&b->list);
        p = quadtree_del(&b->tree, &planet_ops);
 
+       _merge_planets(a, b);
        free(b);
        return tree_to_planet(p);
 }