Repository navigation
Description
_gx_system_canvas_refresh() returns whatever the last _gx_canvas_drawing_initiate() of the last dirty area of the last root window happened to return, and _gxe_system_canvas_refresh() forwards that straight to the application. GX_NO_VIEWS is not an error, but it reaches the caller as though the refresh had failed.
Line references are against dev at d6a06679.
The defect
common/src/gx_system_canvas_refresh.c declares status = GX_SUCCESS at line 282 and returns it at line 455. In between, two _gx_canvas_drawing_initiate() calls assign to it:
| Line | Call | Assigns status? |
|---|---|---|
| 333 | outer, once per visible root window | yes — added by 8a35f690 (#158) |
| 373 | inner, once per dirty area | yes — pre-existing |
From common/src/gx_canvas_drawing_initiate.c the value can be:
| Value | Meaning |
|---|---|
GX_SUCCESS |
drew normally |
GX_NO_VIEWS |
normal condition — the root window's view list is empty |
GX_DRAW_NESTING_EXCEEDED |
context stack full |
GX_INVALID_MEMORY_SIZE |
partial-frame-buffer configurations only |
GX_NO_VIEWS is handled deliberately by the refresh — line 376 draws the children of a viewless root window — and then leaked to the caller.
Why it matters
common/src/gxe_system_canvas_refresh.c:74-77 passes the value through unmodified, so the public gx_system_canvas_refresh() API can report failure for a refresh that did exactly what it was asked. The obvious application idiom
if (gx_system_canvas_refresh() != GX_SUCCESS)
{
/* handle the error */
}reports a spurious failure, and which value comes back depends on the order of the dirty list — so it is not reproducible from the application's point of view.
Nothing inside GUIX misbehaves today: every in-tree caller ignores the return value (gx_animation_complete.c:180, gx_animation_slide_landing.c:247, gx_system_thread_entry.c:104,119, gx_touch_driver_generic_resistive.c ×7, gx_window_execute.c:98,112). The exposure is entirely at the API boundary.
This is pre-existing, not a #158 regression
git show 8a35f690^:common/src/gx_system_canvas_refresh.c already had the inner assignment and return status. The outer call was there too, with its return value discarded. #158 added a second source for the leak; it did not create it. Please don't attribute it to that commit alone.
Suggested fix — pick a contract first
(a) Keep the drawing status out of the completion status (recommended). Give the two _gx_canvas_drawing_initiate() calls a local draw_status, leave status alone, and return GX_SUCCESS. This is what the function's name and its OUTPUT: status — Completion status header promise, and it is the same shape as the fix applied to _gx_animation_start() in #175.
There is a useful precedent in the same file: _gx_system_canvas_draw_partial_canvas() (the static function at line 74, compiled under GX_ENABLE_CANVAS_PARTIAL_FRAME_BUFFER) assigns _gx_canvas_drawing_initiate()'s result to a local at line 188, uses it for control flow, and returns GX_SUCCESS unconditionally at lines 91 and 236. Its caller at line 323 discards the result. That is exactly option (a), already written, one function above the defect.
(b) Decide GX_NO_VIEWS is a meaningful result and document it. Then it must be produced deliberately and consistently — e.g. "GX_NO_VIEWS if no root window had any views" — rather than being whatever the last dirty area yielded. More work, and it is not obvious that any caller wants it.
Either way, check whether the return value of gx_system_canvas_refresh() is documented in rtos-docs-asciidoc; if so it needs a matching update.
Regression test
No test asserts the return value of gx_system_canvas_refresh() today — which is why this was never caught. Whichever option is chosen, ship one. test/guix_test/regression_test/tests/validation_guix_canvas_draw_nesting_overflow_no_output.c is a good model: a *_no_output test using EXPECT_EQ on API return values rather than comparing frames.
Cover at least a normal refresh, a refresh where a visible root window has an empty view list, and — if GX_DRAW_NESTING_EXCEEDED turns out to be reachable here — the context-stack-full case.
What is established, and what is not
Established (read from source at d6a06679, verified still present):
statusis written by both_gx_canvas_drawing_initiate()calls and returned at line 455._gxe_system_canvas_refresh()forwards it to the application.- No in-tree caller checks it.
- The inner assignment and
return statuspredate Fixed issue 148 draw context stack overflow #158; the outer assignment was added by it.
Not established:
- That the leak is ever observed. Under gdb (
break gx_system_canvas_refresh.c:455) the function returned0on every call across 11 tests:guix_animation_complete,guix_all_widgets_16bpp_canvas_animation,guix_all_widgets_accordion_menu,guix_canvas_hide,guix_canvas_hardware_layer,guix_canvas_delete_no_output,guix_canvas_drawing_complete,guix_root_window_focus_no_output,guix_screen_stack,guix_animation_drag_tracking,guix_animation_stop. This is a defect by inspection, not a diagnosed failure. - Whether
GX_DRAW_NESTING_EXCEEDEDorGX_INVALID_MEMORY_SIZEare reachable at line 333 or 373 in practice. - Whether any out-of-tree application depends on the current behaviour. Since this changes what a public API returns, that is worth a moment's thought before (a) is adopted.
How to observe it
The regression harness is Linux-only.
cd test/guix_test/cmake/build/default_build_coverage/regression
cat > /tmp/probe.gdb <<'EOF'
set breakpoint pending on
set confirm off
handle SIGUSR1 nostop noprint pass
handle SIGUSR2 nostop noprint pass
handle SIGALRM nostop noprint pass
break gx_system_canvas_refresh.c:455
commands
silent
printf "REFRESH_RET=%d\n", status
continue
end
run
EOF
gdb -q -batch -x /tmp/probe.gdb \
--args ./guix_animation_complete -checksum -gpath ../../../../golden_files/ \
2>&1 | grep -oE 'REFRESH_RET=[0-9]+' | sort | uniq -cThe GUIX library is a shared object, so breakpoints need set breakpoint pending on. The ThreadX Linux port uses SIGUSR1/SIGUSR2 for scheduling and they must be passed through, or gdb stops constantly. Stepping (next, step) is unreliable in this port — use breakpoints with commands/continue blocks.
Related
- Fixed animation start regression that prevented animations from running #175 — the same class of defect (
_gx_canvas_drawing_initiate()'s return value assigned to a variable that is also a function's completion status) in_gx_animation_start(). That one broke three tests and is fixed. - _gx_widget_block_move() drops the repaint when the canvas has no views #181 — the companion finding from the same audit of Fixed issue 148 draw context stack overflow #158:
_gx_widget_block_move()losing its dirty-area fallback. Same shape, different function.
Activity