Closed brianapps closed 3 years ago
Thank you so much for this detailed report! I'll be looking into fixing this shortly.
I looked into this a bit more and it looks like what ends up happening is with the guard enabled, the ranges variable ends up looking like:
[ -inf, -inf, +inf ]
Since the render loop then looks for the parabola vertex just below +inf, this works out even if it's odd. This neatly resolves the problem I had handling infinities and finally makes this code more generalized. I was able to remove two additional scans over the array that converted to and from infinite and finite representations which leads to a small speedup.
Thanks for your help!
Thanks a lot for doing this, I really appreciate your hard work putting this library together. I've checkout out your branch and run it over a much larger problem case -- it works and everything looks good to me. Pleased to hear this led to improvements elsewhere.
For some reason, removing the tofinite/toinfinite passes didn't work so well on Windows. I don't have access to a copy to experiment so I added it back. I'll make a release in a bit.
You can get the newest version 2.0.3. Thanks again for your detailed report!
Reproduction steps
When I run this code.
The process exits with a segmentation fault
I'd expect the script to produce these distances
The same issue occurs with the equivalent C++ code.
Discussion
When debugging I noticed situations in
squared_edt_1d_parabolic
where the variablek
becomes negative and memory outside various buffers is accessed.With the above data set, the routine attempts to calculate the intercept of two parabolas using this equation (grabbed from the README).
The parameters are
w=0.5
,r=1
,q=0
,f(r)=0.25
andf(q)=INFINITY
. This givess
at-6.80e38
but this exceeds the limit of a float sos
ends up set to-INFINITY
.When it reaches the while block
This condition is true for
k=0
(becauseranges[0]
is initialised to-INFINITY
).k
then becomes-1
and the code ends up accessing values outside various buffers. A segmentation fault tends to follow at some point.I believe that with anisotropic weights > sqrt(1/2),
s
will always be greater than-INFINITY
and the under-run condition never occurs. My gut feeling is adding a guard onk
(in two places) e.g.Will fix the issue but I don't know the code well enough to be sure.
Workaround
Scale the anisotropic weights so they are at least one and divide the results by this scale. e.g.