From acd3330bcdcbc4fa9fbf82c5e484ccea42918223 Mon Sep 17 00:00:00 2001 From: aerom Date: Thu, 30 Apr 2026 16:00:14 -0400 Subject: [PATCH] fix: _h2r parses rgb() strings to prevent NaN in canvas gradients MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _darken3D / _lighten3D return 'rgb(r,g,b)' CSS strings. When those values were passed as colList to drawCylinder/drawSphere, _cylGrad called _lighten3D(col) → _h2r('rgb(...)') → parseInt('rg',16)=NaN, causing addColorStop to throw and killing ALL pillar/tower/sphere buoy symbols. Fix: _h2r now detects the 'rgb(' prefix and extracts the three integers via regex before falling through to the existing hex path. Co-Authored-By: Claude Sonnet 4.6 --- frontend/js/map.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/js/map.js b/frontend/js/map.js index 8db604e..6b93531 100644 --- a/frontend/js/map.js +++ b/frontend/js/map.js @@ -352,8 +352,12 @@ function _tmX(ctx, cx, cy, r, col) { } // ── True-3D colour helpers ──────────────────────────────────────────────── -function _h2r(hex) { // hex → [r,g,b] - hex = hex.replace('#',''); +function _h2r(hex) { // hex or rgb() → [r,g,b] + if (typeof hex === 'string' && hex.startsWith('rgb')) { + const m = hex.match(/\d+/g); + return m ? [+m[0], +m[1], +m[2]] : [0, 0, 0]; + } + hex = (hex || '').replace('#',''); if (hex.length === 3) hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]; return [parseInt(hex.slice(0,2),16), parseInt(hex.slice(2,4),16), parseInt(hex.slice(4,6),16)]; }