Commit 39f395f8 authored by vertighel's avatar vertighel
Browse files

fits-viewer.js: evita lo starvation del fallback REST a dinamica manuale

Con autoRange=false, ogni push "fits-preview" lanciava un fallback REST
(due round-trip: /png poi /panoramic) invece del semplice decode locale
del PNG gia' pronto. Su un link non istantaneo, quel round-trip poteva
durare piu' del periodo tra due push: il push successivo minava un seq
piu' recente e invalidava (via _isPrimaryStale) il rendering ancora in
volo del precedente, all'infinito — il canvas principale restava
bloccato sull'ultima immagine dipinta con successo, mentre il magnifier
(che usa _tileSeq, un meccanismo indipendente) continuava a funzionare.

Aggiunto _primaryRangeRefreshBusy: se un fallback e' gia' in corso, i
push che arrivano nel frattempo vengono ignorati invece di avviarne uno
concorrente — il prossimo push libero riprende il refresh normalmente.
Corretta anche la modalita' 'fits' (WebGL), che il fallback ignorava
del tutto: ora richiama _renderFits() invece di _renderPng() quando
il canvas e' in quella modalita'.
parent 96d2ee94
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -148,6 +148,14 @@ export class FitsViewer {
        this._primarySeq        = 0;
        this._primaryPendingSeq = 0;

        // Re-entrancy guard for the WS-triggered REST fallback used when
        // autoRange is false (see _listenStream/"fits-preview"): a REST
        // round-trip can outlast the push interval on a slow link, so
        // without this a newer push would keep invalidating the still
        // in-flight previous one via the seq guard above and the canvas
        // would never finish painting.
        this._primaryRangeRefreshBusy = false;

        // ── Right-drag range-adjustment state ──────────────────────────────
        this._rdrag = null;  // set to {startX, startY, currentMin, currentMax} while dragging

@@ -683,10 +691,22 @@ export class FitsViewer {
                    // The pushed PNG is pre-rendered server-side with the
                    // server's own auto-range, ignoring our vmin/vmax. Once
                    // the user has set a manual range, re-render via REST
                    // instead so the new frame respects it.
                    if (this._primary.mode === 'png') await this._renderPng();
                    // instead so the new frame respects it. Skip if a
                    // previous fallback render is still in flight — see
                    // _primaryRangeRefreshBusy.
                    if (this._primaryRangeRefreshBusy) return;
                    this._primaryRangeRefreshBusy = true;
                    try {
                        if (this._primary.mode === 'fits') {
                            await this._renderFits();
                        } else {
                            await this._renderPng();
                        }
                        await this._refreshPanoramic();
                        this._redrawOverlay();
                    } finally {
                        this._primaryRangeRefreshBusy = false;
                    }
                    return;
                }