Skip to content
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

Refresh Fix for TileGrid #152

Merged
merged 1 commit into from
Jan 22, 2025
Merged

Refresh Fix for TileGrid #152

merged 1 commit into from
Jan 22, 2025

Conversation

FoamyGuy
Copy link
Contributor

@FoamyGuy FoamyGuy commented Jan 21, 2025

@ladyada
Resolves: #150

I believe the root cause of the issue is the refresh thread running on it's own cycle in the background while the user code is manipulating Groups, TileGrids, Bitmaps etc. which cause refresh to be needed. I think there is a period of time during the refresh process after _get_refresh_areas() has been called for a given object, and before _finish_refresh() gets called for that same object. During that window of time if the user code manipulates the object making it need to be re-drawn it won't actually get drawn because _finish_refresh() gets called first which makes the next call to _get_refresh_areas() not return any areas to draw because _finish_refresh() clears / resets the dirty area to empty.

This change resolves it by adding a _needs_refresh bool that gets set to True whenever any change that triggers a refresh occurs. Then inside _finish_refresh() we only do the finish logic when that bool is False. The bool is flopped to False in _get_refresh_areas() once we know that our triggered refresh is in process.

I tested this fix successfully with the reproducer from the issue.

Unrelated to the issue above, I also removed a duplicated _finish_refresh() function inside of Bitmap. The remaining function is here: https://github.com/adafruit/Adafruit_Blinka_Displayio/blob/main/displayio/_bitmap.py#L294

@ladyada ladyada requested a review from makermelissa January 21, 2025 15:52
Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Makes sense the way you did it because we are using threads and the code I ported from circuitpython doesn't have that challenge.

@FoamyGuy FoamyGuy merged commit c35bd2c into adafruit:main Jan 22, 2025
1 check passed
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.

auto_refresh doesn't work in some cases
2 participants