Skip to content

fix: -fno-finite-math-only after -ffast-math for #369 - #407

Open
eamondo2 wants to merge 1 commit into
calf-studio-gear:masterfrom
eamondo2:patch-1
Open

eamondo2 wants to merge 1 commit into
calf-studio-gear:masterfrom
eamondo2:patch-1

Conversation

@eamondo2

@eamondo2 eamondo2 commented Jul 22, 2026 •

Copy link
Copy Markdown

(Copied from response in issue #369)

So I was able to actually resolve this with some trial and error, turns out the problem is in the compile options and their ordering.

Specifically here:

add_compile_options(-ffast-math -finline-limit=80 -finline-functions -finline-functions-called-once)

That needs to be changed to:

add_compile_options(-ffast-math -fno-finite-math-only -finline-limit=80 -finline-functions -finline-functions-called-once)

The order matters, -fno-finite-math-only must come after -ffast-math (last flag wins), which re-enables inf/NaN semantics while keeping the rest of fast-math for the DSP.

The reason, as best I've been able to establish, is that a recent cairo bump (cairo >= 1.18) causes it to silently drop entire paths when calling cairo_line_to if any coordinate is non-finite.
That matters because the analyzer uses INFINITY as a flag for "skip this pixel" when drawing. So with -ffinite-math-only enabled, the compiler assumes infinities can't exist and folds the line-graph widget's guard data[i] < INFINITY to constant-true. Technically -ffast-math was always incompatible, it just never showed up here before.

Bars/boxes/spectralizer views survive because they pass coordinates through (int)y casts before cairo, so no non-finite value ever reaches the path.

I've got the patched version working on my box currently, using a nix substituteInPlace expr. to trial it.

calf = prev.calf.overrideAttrs (old: {
    postPatch = (old.postPatch or "") + ''
      substituteInPlace src/CMakeLists.txt \
        --replace-fail "-ffast-math" "-ffast-math -fno-finite-math-only"
    '';
  });

@cupakm

cupakm commented Sep 28, 2026

Copy link
Copy Markdown

Hi, I also ran into not seeing Analyser's spectrum and can independently confirm:

Calf 0.90.9 calflv2gui.so built with GCC 15.2.0 (Ubuntu) and the flags from src/CMakeLists.txt, in Ardour 9.8 (built against Ardour's bundled GTK2 fork, but the mechanism below doesn't depend on GTK). The phase correlation display updates, but the Analyzer spectrum line stays empty. Adding -fno-finite-math-only after -ffast-math, as this PR does, fixes it.

Root cause: analyzer::draw() (src/analyzer.cpp) marks points that should not be drawn with data[i] = INFINITY, and calf_line_graph_draw_graph() (src/ctl_linegraph.cpp) skips them with data[i] < INFINITY. -ffast-math implies -ffinite-math-only, so GCC folds that comparison to true. Every marker is then drawn: in line mode as cairo_line_to(ctx, x, y) with y = -inf. In a standalone reproduction of that drawing code with cairo 1.18.4, the folded line path paints 0 pixels and cairo reports no error, while the bar path, which casts (int)y before cairo_rectangle(), still paints. That is consistent with Bars working and Lines not (#369). Curves that never contain INFINITY, like the Filter response, are unaffected.

@JohannesLorenz
JohannesLorenz self-requested a review October 12, 2026 09:37
@JohannesLorenz

Copy link
Copy Markdown
Collaborator

Thanks for submitting this PR, it seems to solve the problem.

Before we merge this, I wonder whether this change might have on other parts of the code, as it will have an effect on all source files. Could this rather be solved locally, i.e. find a very high value that serves as a sentinel, but is not INFINITY? Would that be safer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants