Sign in to follow this  
Baesky

How to debug the complex data structure and algrithms such like quadtree, BSP, octree?

Recommended Posts

Baesky    167

Hi, recently i worte my own implements of quadtree, but i encountered some bug in my algrithm. I found it difficult to debug the bug because the algrithm and data structure is complex than others.

I wanna known how to debuging in this situation if you were me?

Thanks advance!

Share this post


Link to post
Share on other sites
HappyCoder    5052
I don't know of any easy answers. But a few things come to mind. First, find a scenerio where you can duplicate the bug evertime. The fewer steps the better. Then drill down with a debugger viewing intermediate values and making sure they match expected output. Also, having some way to visualize the quadtree is usefull, drawing it out to the screen for example.

Another thing to concider is to make automated tests. When you write the tests make then simple but be sure to cover common occurences. For a quadtree, make a test for when the object being added intersects multiple quadrants. Make a test that overflows a quadrant so it has to be split. Making automated test helps you think of corner cases to thouroghly test your algorithm in small parts so you can have more confidence it works as a whole.

Share this post


Link to post
Share on other sites
rozz666    896

I would split the algorithm into the smallest pieces that are reasonable and unit test every possible scenario. Then the only bugs that could occur would be integration errors, which I would cover with module tests.

Share this post


Link to post
Share on other sites
RobTheBloke    2553

Unit test *everything*. Some debug rendering *may* be useful, but only as a tool to help decide what to test next.....

A GUI based editor might be useful (i.e. tree view window, with attribute editor listing information about each node in the tree). That won't help you find problems in the implementation though, just as a tools to inspect the data... 

Edited by RobTheBloke

Share this post


Link to post
Share on other sites
unbird    8336
I occasionally find log-files useful to track down bugs. E.g. for big loops or structures dumping temp vars or debug calculations in tabular form is IMO easier too inspect than repeatedly run-break with an interactive debugger.
 
Currently I (ab)use a D3D11 append buffer to "log" debug values from compute shader wink.png

Share this post


Link to post
Share on other sites
deftware    1778

I work with tree structures by starting very small, one level with a node and just its children. I see how everything operates there, and then start making the tree deeper, to make sure any recursion doesn't start throwing things off.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this