Raycast with filter not working

I am trying to change my raycast, that used to get the closest fixture, so that it gets the closest that is not from category LEVEL0. I saw the following post:
viewtopic.php?f=3&t=4343
And looked at the solution, but it doesn't work for me. My RayCast class is like this:

Code: Select all

    private static class RayCast implements RayCastCallback {
        Fixture f;
        Vector2 point;
        float fraction;
       
        public RayCast() {
           this.fraction = 1f;
        }
       
        @Override
        public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
           if (fixture.getFilterData().categoryBits == Corpo.LEVEL0)
              return 1f;
           
           if (fraction <= this.fraction) {
               this.f = fixture;
               this.point = point;
               this.fraction = fraction;
           }
           return 1f;
        }
    }

Just like the one provided by Erin, but it doesn't work: it ignores the right bodies only sometimes, and sometimes ignores other bodies as well. The first if is called only in the right moments, I guess, and even though this happens. The regular objects collision works fine, so I don't think it is a problem with the categories setup. I tried other alternatives too: return -1 in the first if should just ignore this collision, but it doesn't work. Anyway, I think it is a Java (jBox2d within libGDX in my case) specific problem, so I am posting it here. Does anyone have a hint about this?
So, after some time, I finally found out what the problem was; something very tricky indeed. It seems that the raycast method uses the same point for every call, so when I did:

Code: Select all

this.point = point;

I actually created a reference to the point, and, sometimes, in further calls it did because it didn't know it could stop already, it messed with my reference. Using the method cpy() to make a copy solved everything.

Original thread: https://box2d.org/forum/viewtopic.php?t=9491