That’s what I am saying - your code’s working on meshes under several conditions! I.e. NOT on every mesh (unknown)…

Checking beyond 10000 is the least problem. You’re NOT checking if your body is closed… The cheapest way to do so is checking the Euler’s formula! If it say “OK”, then it is “OK”… If not - a whole bunch of problems may be in place.

Shown is the default cube, subdivided twice, and one internal face added:

So for a point (0.25, 0.25, 0.25) which is obviously INSIDE, using the ray along (1,0,0) will give you the faulty result cause the ray will intersect 3 faces. While using the ray (0,1,0). for example, will give you the correct result!

Frankly, in such a situation I woulnd rely very much on THAT algorithm…

If Euler’s formula isnt TRUE, in addition to holes, you may expect overlapped faces, orphan verts and edges, etc. Which you also dont check as well…

In conclusion - again - your code is pretty good and working under some conditions to the mesh examined.

Regards,