Found raycasting bug

Topics: Developer Forum
Jul 18, 2011 at 1:40 PM

I have found a bug in farseer that causes a ray cast to return a result with a fraction larger than MaxFraction, fortunately there a simple fix


        public void RayCast(RayCastCallback callback, Vector2 point1, Vector2 point2)
            RayCastInput input = new RayCastInput();
            input.MaxFraction = 1.0f;
            input.Point1 = point1;
            input.Point2 = point2;

            ContactManager.BroadPhase.RayCast((rayCastInput, proxyId) =>
                                                      FixtureProxy proxy = ContactManager.BroadPhase.GetProxy(proxyId);
                                                      Fixture fixture = proxy.Fixture;
                                                      int index = proxy.ChildIndex;
                                                      RayCastOutput output;
                                                      bool hit = fixture.RayCast(out output, ref rayCastInput, index);

                                                      if (hit)
                                                          float fraction = output.Fraction;
                                                          Vector2 point = (1.0f - fraction) * input.Point1 +
                                                                          fraction * input.Point2;
                                                          return callback(fixture, point, output.Normal, fraction);

                                                      //return input.MaxFraction; // input.MaxFraction is always 1 causing MaxFraction to reset
return rayCastInput.MaxFraction; }, ref input); }



Aug 18, 2011 at 12:45 AM

Yay. You found it, you rock. I raised this issue in the past but couldn't figure out what was happening.

We should ensure that this gets logged as a bug and fixed for the next release.

Once again you're awesome!

Aug 23, 2011 at 8:58 AM

You totally rock! I've been looking for this bug for ages!

May 5, 2012 at 5:08 PM

Thank you!

May 26, 2012 at 11:25 PM

I couldn't find this bug in the issue tracker. Has someone added it there yet? If yes, please post a link here. If not, let's do it finally! :-)

Jun 5, 2012 at 9:21 PM
Edited Jun 5, 2012 at 9:22 PM

For the record, I created an issue in the bug tracker that links to this thread: