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

avoid ZeroDivisionError with ssd1327 #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

douglaspkelly
Copy link

For a ssd1327 rows_per_buffer is 104/106, which rounds/truncates to zero, causing ZeroDivisionError on line 371 (subrectangles=...).

Tested with a ssd1327 on raspberry pi 4.

rows_per_buffer is 104/106, which rounds/truncates to zero, causing ZeroDivisionError on line 371 (subrectangles=...).
@makermelissa
Copy link
Collaborator

Hi, this is basically ported from https://github.com/adafruit/circuitpython/blob/main/shared-module/busdisplay/BusDisplay.c#L235-L254.

In lines 359-360, it's already being set to 1.
For lines 362-368, I'm trying to figure what set of values would set it back down to zero and if this is a problem in the main displayio code.

@douglaspkelly
Copy link
Author

For lines 362-368, I'm trying to figure what set of values would set it back down to zero and if this is a problem in the main displayio code.

Here are values that ultimately result in division by zero:

buffer_size=12
pixels_per_word=8
clipped.width()=102
So, rows_per_buffer = 12 * 8 // 102 = 0 (which is bumped to 1 on the next if statement.

Later:
self._core.colorspace.depth=4
self._core.colorspace.pixels_in_byte_share_row=True
So, pixels_per_byte = 8 // 4 = 2

Then:
rows_per_buffer (1) % pixels_per_byte (2) = 1 (!=0), so then:
rows_per_buffer -= 1 % 2 = 1-1 = 0, resulting in the subrectangles division being by zero.

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