Skip to content

fix: overflow, stale aircraft age-out, dead code, per-frame redundancies - #92

Open
dreamiurg wants to merge 1 commit into
MatixYo:mainfrom
dreamiurg:fix/review-bugfixes
Open

dreamiurg wants to merge 1 commit into
MatixYo:mainfrom
dreamiurg:fix/review-bugfixes

Conversation

@dreamiurg

Copy link
Copy Markdown
Contributor

Five small, independent fixes found while reviewing the radar drawing and ADS-B fetch paths.

Overflow in segmentIntersectsDisc — the quadratic discriminant b*b - 4*a*c was computed in int. With screen-scale coordinates b*b overflows 32 bits, so runway segments crossing the scope were sometimes classified wrongly. Now computed in float with sqrtf.

millis() wraparound in the fetch loops — performGetWithPoll and readResponseBodyWithPoll used millis() + timeout as an absolute deadline. That comparison breaks when the counter wraps (~49 days uptime), turning the loop into an instant timeout or an effectively infinite one. Switched to the wrap-safe millis() - start < timeout idiom.

Stale aircraft age-out — if fetches start failing (WiFi drop, API outage), the last good aircraft list stayed on screen indefinitely, showing positions that are minutes old as if they were live. adsb::lastSuccessMs() is now recorded on each successful fetch, and drawAircraft treats the list as empty after 15 s without one. An empty scope is honest; a frozen one is not.

Dead code removed — kAdsbFetchRadiusScale (superseded by radar::fetchRadiusKm()), rangeIndex(), and s_scale_label_max_w/s_scale_label_h together with the boot-time loop that measured every range label to fill them. Nothing read any of them.

Per-frame redundancies — initPalette() was called inside drawStaticGrid although both callers already call it before rendering. initTagLabelMetrics()/applyTagStyle() were re-applied per aircraft (twice each, via drawAircraftTag and measureTagBlockWidth); they are now hoisted to once per frame before the tag loop.

User impact: correct runway clipping near the rim, no wraparound stall after long uptime, no stale traffic shown during an outage, slightly less per-frame work.

Tested: builds for env:supermini; ran on an ESP32-C3 Super Mini + GC9A01 (combined with other local changes).

🤖 Generated with Claude Code

https://claude.ai/code/session_017qjXYQiTkbgyVV7ZzvKzA3

- segmentIntersectsDisc: compute the discriminant in float (int overflowed)
- adsb_client: wrap-safe millis() deadlines in the poll loops
- adsb_client: expose lastSuccessMs(); age out aircraft after 15 s stale
- drop dead kAdsbFetchRadiusScale, rangeIndex(), s_scale_label_* metrics
- hoist initPalette/initTagLabelMetrics/applyTagStyle out of per-item paths

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017qjXYQiTkbgyVV7ZzvKzA3
@MatixYo

MatixYo commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Could you resolve conflicts @dreamiurg ?

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.

2 participants