Page 1 of 1

Ray Cast error when there are no entities.

Posted: Mon Aug 22, 2011 3:31 pm
by Spankenstein
If I cast a ray after removing the last entity in the scene/space then I get the following error:
Object reference not set to an instance of an object.
in the following method:

Code: Select all

        public bool RayCast(Ray ray, float maximumLength, IList<BroadPhaseEntry> entries)
        {
            hierarchy.root.GetOverlaps(ref ray, maximumLength, entries);       // <------ HERE

            return entries.Count > 0;
        }
Steps to error:

Code: Select all

                            BEPUphysics.Entities.Prefabs.Box box = new BEPUphysics.Entities.Prefabs.Box(Vector3.Zero, 1, 1, 1);
                            space.Add(box);
                            space.Remove(box);

if (space.RayCast(new Microsoft.Xna.Framework.Ray(cursorRay.Origin, cursorRay.Direction), 1000.0f, results))

// error
Maybe needs a check for the current entity count in the method?

Re: Ray Cast error when there are no entities.

Posted: Mon Aug 22, 2011 4:50 pm
by Norbo
Dadgummit, I've fixed various forms of this bug twice now. Third time's the charm! http://bepuphysics.codeplex.com/SourceC ... evelopment

Re: Ray Cast error when there are no entities.

Posted: Mon Aug 22, 2011 8:27 pm
by Spankenstein
Thanks for the fix :)