GNOME Bugzilla – Bug 372671
Turning on loglog smoothing crashes FractalExplorer.
Last modified: 2006-11-15 17:05:48 UTC
As soon as you click the box beside "Use loglog smoothing" on the Colors tab, Fractal Explorer will die with a segmentation fault. The problem is in the formula for 'adjust' in both the Dialogs.c and FractalExplorer.c files. The formula is: adjust = log (log (x * x + y * y) / 2) / log (2); The log (x * x + y * y) will return a 0 or negative value for certain combinations of x and y. This will result in adjust being set to 'nan' (ie. not a number) when this value is passed to the outer log call. The segmentation fault occurs a few lines down when an array lookup is performed based on an offset calculated using the bad value of adjust.
Given this analysis, it should be easy to fix the bug. Kevin, is is right to assume that you are already working on a fix?
I tried a simple fix of setting adjust to 0 if the result of the first log is less than or equal to 0 but it causes noticeable (and not particaularly good) changes in the generated image. It would prevent the segfault so it may be worth making this change until a better fix comes along.
The crash occurs because floating point "inf" is used for array index calculations. This inf is generated by the log(log(modulus)), when modulus < e (the base for natuaral logarithms). modulus is < 4 when the innermost loop exits after the entire loop has run, i.e., it doesn't break (the modulus doesn't cross the "escape" radius of 2). The loop has a counter so we don't wait indefinitely for the modulus to escape. So there's a maximum value for this counter (called the loop counter). If the loop has exited after a full run, it already means that the loop counter is clamped at the maximum value. So mu (alpha) can be equal to 0.0. This region represents the entire innermost lake of the mandelbrot set. We basically check if modulus < e and use alpha = 0.0. Even if e <= modulus < 4, log(log(modulus)) will return a very small (non-negative) real number which won't affect the colormap index. Patch is attached below. But we won't use this patch as we'll first clean up the Fractal Explorer plug-in a bit to remove redundant code.
Created attachment 76377 [details] [review] Patch for fixing this bug which implements the explanation in the previous comment
No loglog: http://www.mukund.org/temp/mandel-plain.png loglog: http://www.mukund.org/temp/mandel-loglog.png
Please use G_E instead of defining M_E. And I would prefer if you would commit this patch (after changing to G_E) before you proceed cleaning up the code. It's better to have multiple smaller commits than one large one.
2006-11-15 Mukund Sivaraman <muks@mukund.org> * plug-ins/FractalExplorer/FractalExplorer.c * plug-ins/FractalExplorer/Dialogs.c: Fixed bug #372671 and made loglog smoothing work again. Closing this bug since the bug originally reported has been fixed.
Fix was merged into the gimp-2-2 branch.