Repository navigation
fix(gfx): platform-dependent drawPolygon default MAXN for low-memory targets - #5288
Conversation
…emory targets drawPolygon defaulted to MAXN=32, CHUNK=64 everywhere: a 4272 B Exact (2139 B ABuffer) stack frame on AVR, more than an Uno's 2 KB of SRAM. Default to 8/16 when !FL_PLATFORM_HAS_LARGE_MEMORY (1032 B / 603 B) and keep 32/64 elsewhere via FL_GFX_POLYGON_DEFAULT_MAXN/_CHUNK. Explicit tiers are unchanged. Fixes #5287
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Memory usage (this PR vs. its merge base)Change in
|
Fixes #5287
Problem
drawPolygondefaulted toMAXN=32, CHUNK=64on every platform. On AVR that is a 4272 B stack frame for the Exact kernel and 2139 B for the ABuffer kernel, measured with avr-gcc 7.3-Os -fstack-usage. Both are larger than an Uno's 2 KB of SRAM, so a default-argument call silently overflows the stack.Fix
The default tier now depends on the platform, through two overridable config macros in
src/fl/gfx/canvas.h:FL_GFX_POLYGON_DEFAULT_MAXNFL_GFX_POLYGON_DEFAULT_CHUNKFL_PLATFORM_HAS_LARGE_MEMORY(host, ESP32, Teensy 4, ...)!FL_PLATFORM_HAS_LARGE_MEMORY(AVR, ESP8266, STM32F1, LPC, ...)All six default-argument sites in
canvas.handgfx.huse them. ExplicitMAXN/CHUNKarguments behave as before. CHUNK does not change the rendered pixels. MAXN only matters for polygons with more than MAXN vertices, which are truncated as before. The doc comments inprimitives.handpoly_abuffer.hnow give the measured stack figures. The host test asserts that the host default stays 32, because the pinned 32- and 34-vertex cases rely on it.Evidence
-fstack-usageframes for the kernel alone, before -> after: Exact 4272 B -> 1032 B, ABuffer 2139 B -> 603 B.canvas.drawPolygon<fl::s16x16>(...): it instantiatesdrawPolygonCore<CRGB, s16x16, true, 8, 16>, and the prologue reserves 0x3FA = 1018 B.bash compile mega --examples PolyShow,PolyDemo,PolyKernels: all three build. The poly examples are filtered out on uno because of their LED buffers.bash test --cpp: 369/369 unit and 98/98 example tests pass.bash lintis clean.Summary by CodeRabbit
New Features
Documentation