Possible issue with QuadTree raycast?

Topics: Developer Forum
Dec 31, 2011 at 12:29 AM
Edited Dec 31, 2011 at 12:30 AM

Hi everyone,

I've been trying to use raycasts with the QuadTree collider, but I was having strange null pointer exceptions. I traced them down to these lines in QuadTree.cs RayCast method:

 

if (IsPartitioned)
    foreach (QuadTree<T> st in qt.SubTrees)
        stack.Push(st);

 

Where qt.SubTrees would be null. This sounded weird as "IsPartitioned" is a property that returns true only when SubTrees is different than null. Could it be that what was intended was something like:

 

if (qt.IsPartitioned)
    foreach (QuadTree<T> st in qt.SubTrees)
        stack.Push(st);

 

This seems to make sense as it's essentially the recursion step for traversing the trees. Fixing it like this solved my issue, but I didn't look into the routine carefully enough to know for sure if it's a real bug or not.

Jan 13, 2012 at 5:02 PM

I ran on the same issue, and your solution seems to work, but I'd like to know if this is a valid solution or it could lead to new bugs.