From 9da428e0c03b32642233ceb8e282f731bf6ad44d Mon Sep 17 00:00:00 2001 From: Christopher Albert Date: Mon, 25 Aug 2025 11:15:02 +0200 Subject: [PATCH 1/3] update: reference issue #317 for colored_contours PDF crash --- BACKLOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BACKLOG.md b/BACKLOG.md index 147036db..33221e35 100644 --- a/BACKLOG.md +++ b/BACKLOG.md @@ -7,7 +7,7 @@ **Infrastructure & Documentation Issues (Lower Priority)** ## DOING (Current Work) -- [ ] Fix GitHub Pages deployment failure - colored_contours example crashes with "End of record" error at fortplot_pdf_drawing.f90:69 in pdf_write_color subroutine +- [ ] #317: Fix GitHub Pages deployment failure - colored_contours PDF runtime crash in pdf_write_color ## BLOCKED (Infrastructure Issues) From d84851fed34022d0b031cee98032c81c464d4ce1 Mon Sep 17 00:00:00 2001 From: Christopher Albert Date: Mon, 25 Aug 2025 11:18:33 +0200 Subject: [PATCH 2/3] fix: add robust RGB validation to pdf_write_color to prevent crashes Add comprehensive validation to pdf_write_color subroutine to handle invalid RGB values (NaN, infinity, out-of-range) gracefully. This prevents 'End of record' crashes when color mapping produces invalid values in contour plots. - Use IEEE_ARITHMETIC intrinsic for NaN/infinity detection - Clamp RGB values to valid [0.0, 1.0] range - Default invalid values to black (0.0) for safety - Fixes colored_contours example crash blocking GitHub Pages Fixes #317 --- src/fortplot_pdf_drawing.f90 | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/fortplot_pdf_drawing.f90 b/src/fortplot_pdf_drawing.f90 index 3a8830c9..0671a011 100644 --- a/src/fortplot_pdf_drawing.f90 +++ b/src/fortplot_pdf_drawing.f90 @@ -7,6 +7,7 @@ module fortplot_pdf_drawing !! Author: fortplot contributors use, intrinsic :: iso_fortran_env, only: wp => real64 + use, intrinsic :: ieee_arithmetic, only: ieee_is_nan, ieee_is_finite use fortplot_vector, only: vector_stream_writer, vector_graphics_state use fortplot_markers, only: get_marker_size, MARKER_CIRCLE, MARKER_SQUARE, MARKER_DIAMOND, MARKER_CROSS implicit none @@ -62,11 +63,37 @@ subroutine pdf_write_stroke(this) end subroutine pdf_write_stroke subroutine pdf_write_color(this, r, g, b) - !! Write PDF color command + !! Write PDF color command with robust validation + !! Validates and clamps RGB values to [0.0, 1.0] range + !! Handles NaN, infinity, and out-of-range values gracefully class(pdf_stream_writer), intent(inout) :: this real(wp), intent(in) :: r, g, b + real(wp) :: r_safe, g_safe, b_safe character(len=64) :: cmd - write(cmd, '(F0.3,1X,F0.3,1X,F0.3," RG")') r, g, b + + ! Validate and clamp R component + if (ieee_is_nan(r) .or. .not. ieee_is_finite(r)) then + r_safe = 0.0_wp ! Default to black for invalid values + else + r_safe = max(0.0_wp, min(1.0_wp, r)) ! Clamp to [0, 1] + end if + + ! Validate and clamp G component + if (ieee_is_nan(g) .or. .not. ieee_is_finite(g)) then + g_safe = 0.0_wp ! Default to black for invalid values + else + g_safe = max(0.0_wp, min(1.0_wp, g)) ! Clamp to [0, 1] + end if + + ! Validate and clamp B component + if (ieee_is_nan(b) .or. .not. ieee_is_finite(b)) then + b_safe = 0.0_wp ! Default to black for invalid values + else + b_safe = max(0.0_wp, min(1.0_wp, b)) ! Clamp to [0, 1] + end if + + ! Write validated color values + write(cmd, '(F0.3,1X,F0.3,1X,F0.3," RG")') r_safe, g_safe, b_safe call this%add_to_stream(trim(cmd)) end subroutine pdf_write_color From 71e149643f45b9e609f9bcf4b21a3831fa77a967 Mon Sep 17 00:00:00 2001 From: Christopher Albert Date: Mon, 25 Aug 2025 11:24:44 +0200 Subject: [PATCH 3/3] plan: add code quality issues found in PR #318 review --- BACKLOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BACKLOG.md b/BACKLOG.md index 33221e35..4e65ff05 100644 --- a/BACKLOG.md +++ b/BACKLOG.md @@ -5,6 +5,9 @@ **🚨 CRITICAL: User-visible PNG/PDF rendering completely broken** **Infrastructure & Documentation Issues (Lower Priority)** +- [ ] #319: Refactor - investigate source of invalid RGB values in contour color mapping +- [ ] #320: Feature - add debug logging for invalid color value corrections +- [ ] #321: Refactor - apply consistent validation pattern to other PDF write functions ## DOING (Current Work) - [ ] #317: Fix GitHub Pages deployment failure - colored_contours PDF runtime crash in pdf_write_color