Ray Cast error when there are no entities.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Ray Cast error when there are no entities.

Post 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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Ray Cast error when there are no entities.

Post by Norbo »

Dadgummit, I've fixed various forms of this bug twice now. Third time's the charm! http://bepuphysics.codeplex.com/SourceC ... evelopment
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Ray Cast error when there are no entities.

Post by Spankenstein »

Thanks for the fix :)
Post Reply