fix(work_plane gui): preserve ROI overlay across RGB live-refresh

Setting canvas.width/height clears its bitmap; the live RGB tick was
firing the img.load handler every second, wiping the ROI rectangle and
breaking the two-click flow (third click was interpreted as restart).

- Only mutate canvas size when image resolution actually changes.
- Re-paint the overlay after each load so the ROI persists.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Adriano Dal PastroandClaude Opus 4.7 committed 2026-05-13 10:58:41 +02:00
1 parent 1bdf407072
commit 92506d62c6
1 file changed
+8 -3
+8 -3
View File
@@ -61,12 +61,17 @@ function startRgbLoop() {
} }
function syncOverlaySize() { function syncOverlaySize() {
overlay.width = img.naturalWidth || 640; // Setting width/height on a canvas wipes its content. Only re-set when
overlay.height = img.naturalHeight || 480; // the image resolution actually changes (rare) so the ROI overlay survives
// each RGB live-refresh tick.
const w = img.naturalWidth || 640;
const h = img.naturalHeight || 480;
if (overlay.width !== w) overlay.width = w;
if (overlay.height !== h) overlay.height = h;
overlay.style.width = img.clientWidth + 'px'; overlay.style.width = img.clientWidth + 'px';
overlay.style.height = img.clientHeight + 'px'; overlay.style.height = img.clientHeight + 'px';
} }
img.addEventListener('load', syncOverlaySize); img.addEventListener('load', () => { syncOverlaySize(); drawOverlay(); });
// Two-click ROI: 1st click = corner A, 2nd click = corner B (rectangle // Two-click ROI: 1st click = corner A, 2nd click = corner B (rectangle
// defined). 3rd click starts a new selection. // defined). 3rd click starts a new selection.