-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix(flex): fix rounding may leave unused space on track with flex_grow #9217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Hi 👋, thank you for your PR! We've run benchmarks in an emulated environment. Here are the results: ARM Emulated 32b - lv_conf_perf32b
Detailed Results Per Scene
ARM Emulated 64b - lv_conf_perf64b
Detailed Results Per Scene
Disclaimer: These benchmarks were run in an emulated environment using QEMU with instruction counting mode. 🤖 This comment was automatically generated by a bot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 16 files
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="src/layouts/flex/lv_flex.c">
<violation number="1" location="src/layouts/flex/lv_flex.c:373">
Multiplying grow_max_size by grow_value before dividing can overflow int32_t (e.g., 9,000,000 * 255 > INT32_MAX), leading to undefined behavior and wrong flex sizes when large coordinates are used.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
AndreCostaaa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a rounding issue in flex layout where grow_unit was always rounded down, sometimes leaving empty space on flex tracks. The fix uses rounding to nearest integer instead of truncation, similar to the existing grid FR implementation (#6255).
Key Changes
- Added
div_round_closesthelper function for rounding division - Changed flex grow size calculation from truncating division to nearest-integer rounding
- Added test case to verify flex tracks are completely filled with growing items
Reviewed Changes
Copilot reviewed 2 out of 16 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/layouts/flex/lv_flex.c |
Implements rounding fix by replacing truncating division with div_round_closest |
tests/src/test_cases/test_flex_grow.c |
Adds test case for flex grow behavior with various combinations of grow values and fixed sizes |
tests/ref_imgs/*.png |
Updated reference images reflecting the fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This looks good, but I'm wondering if simply adding rounding operations can really avoid all errors? For example, the current grow is 1:1:1, but the total width is 10. Can the current algorithm solve this? |
04eb566 to
1d58f57
Compare
|
The 10 into 1:1:1 example was working even before. That's because each iteration of the loop only looks at the remaining
But lets look at 10 into 4:4:4 for an extreme example, which should be similar. Before:
Instead, with the improved rounding, each element is at most 1 off the ideal size, and the last iteration will have no rounding at all:
Rebased to fix conflict in reference images. |
1d58f57 to
b633e65
Compare
b633e65 to
5713f01
Compare
A flex track containing items with flex grow (without max width) should always be filled completely.
Before,
grow_unitis always rounded down, somtimes leaving empty space on flex tracks. Adds a test case to show the issue and fixes it analogously toGRID_FR(#6255).tests/ref_imgs/flex_grow.pngbefore (note how pixels of the red container are visible at the end of some rows):