Skip to content

Fix GR text-state corruption causing persistent layout assertion failures#5736

Open
AJ0070 wants to merge 4 commits intoJuliaPlots:v2from
AJ0070:fix/4816
Open

Fix GR text-state corruption causing persistent layout assertion failures#5736
AJ0070 wants to merge 4 commits intoJuliaPlots:v2from
AJ0070:fix/4816

Conversation

@AJ0070
Copy link
Copy Markdown

@AJ0070 AJ0070 commented Apr 24, 2026

Fixes a GR backend state-corruption bug behind issue #4816 where plotting with non-finite text coordinates/extents could poison subsequent plots in the same session and trigger layout assertions (total_plotarea_vertical > 0mm / total_plotarea_horizontal > 0mm).

Root cause

When GR was asked to draw or measure text at invalid coordinates (for example, annotate! with NaN positions, or labels/ticks after invalid log-scale inputs), GR could return non-finite text extents (inqtext / inqtextext). Those values propagated into subplot padding and layout calculations, causing assertion failures. Because GR state persisted, later unrelated plots also failed until restart.

Fix

In GRExt.jl:

  • gr_text(...): skip text draw when (x, y) is non-finite.
  • gr_inqtext(...): sanitize non-finite returned text bounds and fall back to finite zero extents.

This prevents non-finite values from entering layout padding math while preserving normal behavior for valid inputs.

Testing

Added regression test in test_misc.jl covering:

  • Non-finite annotation reproducer (including repeated call and history dependence)
  • Invalid negative log-scale case followed by a valid labeled log-scale plot

Strengthened test path to renderer-level checks (show(..., MIME("image/png"), ...)) so GR drawing and measuring is exercised directly.

Additional GR stress verification in a clean environment (repeated bad → good render cycles, including twinx) completed without reintroducing assertion failures or session poisoning.

Attribution

Things to consider

  • Does it work on log scales?
  • Does it work in layouts?
  • Does it work in recipes?
  • Does it work with multiple series in one call?
  • PR includes or updates tests?
  • PR includes or updates documentation?

@AJ0070
Copy link
Copy Markdown
Author

AJ0070 commented Apr 24, 2026

The code block mentioned in the issue description works fine locally but there is failure on CI. I am trying to figure it out. It would be great if someone could help out.

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.

1 participant