]> git.itanic.dy.fi Git - sdl-planets/commitdiff
quadtree.c: Improve debuggin capabilities
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 24 Apr 2010 10:48:12 +0000 (13:48 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 24 Apr 2010 10:48:12 +0000 (13:48 +0300)
-Flush out prints immedeatly. This will ensure prints get out even
 though execution is halted to a breakpoint.

-Add some extra debug messages

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

index a914f66324a8e0a6ba09d5ccfc50bd6d0c3c1128..de59a2f61c6ead0b40b77b8ece67ac89fe23c956 100644 (file)
@@ -21,14 +21,22 @@ static void validate_subtree(const struct quadtree *node)
        long int children;
        children = 0;
 
+       if (!node) {
+               printf("Attempted to validate a null pointer\n");
+               fflush(stdout);
+               trap();
+       }
+
        for (i = 0; i < 4; i++) {
                if (!node->child[i])
                        continue;
 
                if (node->child[i]->parent != node) {
-                       printf("%s:%d Fatal! Tree inconsistency detected "
-                              "at child %d in node %p\n",
-                              __func__, __LINE__, i, node);
+                       printf("%s:%d Fatal! Tree inconsistency detected at "
+                              "child %d %p in node %p, incorrent parent %p\n",
+                              __func__, __LINE__, i, node->child[i], node,
+                              node->child[i]->parent);
+                       fflush(stdout);
                        trap();
                }
 
@@ -37,6 +45,7 @@ static void validate_subtree(const struct quadtree *node)
                                printf("%s:%d Fatal! Tree loop detected "
                                       "at child %d in node %p\n",
                                       __func__, __LINE__, i, node);
+                               fflush(stdout);
                                trap();
                        }
                }
@@ -56,6 +65,7 @@ static void validate_subtree(const struct quadtree *node)
                printf("%s:%d Tree statistics inconsistency detected! "
                       "child count mismatch. Expected %ld, got %ld\n",
                       __func__, __LINE__, children, node->children);
+               fflush(stdout);
                trap();
        }
 
@@ -78,6 +88,7 @@ static void validate_subtree(const struct quadtree *node)
                printf("%s:%d Tree statistics inconsistency detected! "
                       "child depth mismatch.",
                       __func__, __LINE__);
+               fflush(stdout);
                trap();
        }
 }
@@ -131,6 +142,11 @@ struct quadtree *quadtree_add(struct quadtree *parent, struct quadtree *new,
        parent->child[ret] = new;
        new->parent = parent;
 
+       if (debug) {
+               printf("adding node %p to parent %p\n", new, parent);
+               fflush(stdout);
+       }
+
        quadtree_recalculate_parent_stats(new, ops);
 
        validate_tree(new);
@@ -187,6 +203,11 @@ struct quadtree *quadtree_del(struct quadtree *node,
        struct quadtree *parent = 0;
        int i;
 
+       if (debug) {
+               printf("Deleting node %p under parent %p\n",
+                              node, node->parent);
+               fflush(stdout);
+       }
        /*
         * We are deleting the root node. This means we have to select
         * a new root node and reconstruct the entire tree under it