1
Vote

ComputeBounds can throw StackOverflowException

description

As it is a recursive method, it can throw StackOverflowException. In fact, the DiskUsage example did so when I ran it on my PC.
 
    protected override void ComputeBounds()
    {
        var row = new Stack<ChildData>();
        var stack = new Stack<ChildData>(ChildDatas);
        var sideLength = GetShortestSide();
 
        while (stack.Count != 0)
        {
            double worst1 = Worst(row, sideLength);
 
            row.Push(stack.Pop());
 
            double worst2 = Worst(row, sideLength);
 
            if (row.Count == 1 || worst1 > worst2)
                continue;
 
            stack.Push(row.Pop());
            ComputeTreeMaps(row);
            row = new Stack<ChildData>();
            sideLength = GetShortestSide();
        }
 
        if (row.Count != 0)
            ComputeTreeMaps(row);
    }
 
 
I've refactored the code around a little so this method won't be a drop in replacement, but it's close enough to be clear, I think.

comments