Skip to content

TilePaletteMapper is misbehaving in absolute newest #10305

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

Closed
FoamyGuy opened this issue May 1, 2025 · 1 comment · Fixed by #10306
Closed

TilePaletteMapper is misbehaving in absolute newest #10305

FoamyGuy opened this issue May 1, 2025 · 1 comment · Fixed by #10306
Labels
bug displayio regression Things that used to work but don't any longer

Comments

@FoamyGuy
Copy link
Collaborator

FoamyGuy commented May 1, 2025

Tested on pyportal titano with adafruit-circuitpython-pyportal_titano-en_US-20250428-main-PR10288-1e4d766.uf2

using this reproducer code

import time
import supervisor
from displayio import Palette
from tilepalettemapper import TilePaletteMapper
import board
import terminalio
import displayio

display = supervisor.runtime.display

time.sleep(1)
p = Palette(8)
p[0] = 0x000000
p[1] = 0xffffff

bbox = terminalio.FONT.get_bounding_box()
main_group = displayio.Group()
display.root_group = main_group

tpm = TilePaletteMapper(p, 2, 10,4)

tg = displayio.TileGrid(terminalio.FONT.bitmap, pixel_shader=tpm,
                        tile_width=bbox[0], tile_height=bbox[1],
                        width=10, height=4, default_tile=0)

main_group.append(tg)

for i in range(40):
    tg[i] = i

while True:
    for y in range(tg.height):
        for x in range(tg.width):
            cur = (x, y)

            tpm[cur] = [1,0] if tpm[cur] == (0,1) else [0,1]
            print(f"{cur}, {tpm[cur]}")
            time.sleep(0.025)

I think there is something wonky going on with the memory that TilePaletteMapper is using internally to store the list of mappings. The first iteration seems to run normally the tiles in the grid get set to white background.

All iterations after the first start getting wonky, instead of simply alternating the colors as the code should it starts erratically changing the color mapping of each tile, some tiles seem to end up with [0, 0] causing them to appear "invisible".

After a handful of iterations the code crashes with this exception:

Traceback (most recent call last):
  File "code.py", line 43, in <module>
TypeError: object '' isn't a tuple or list

which points to the line print(f"{cur}, {tpm[cur]}") but I don't understand what the error means or why it comes up after several iterations seemingly randomly. I believe that as the mappings are getting set it's actually clobbering other memory and eventually overwrites something important that ends up leading to this error.

Not with this exact reproducer code, but with similar TPM manipulations I had a hard fault memory error occur a few times as well which also leads me to the suspicion that something wonky is happening with the internal memory in use by TPM.

Running the exact same code on 9.2.7 and 10.0.0-alpha.2 results in the expected behavior of black / white colors alternating with each iteration.

@FoamyGuy FoamyGuy added bug displayio regression Things that used to work but don't any longer labels May 1, 2025
@FoamyGuy
Copy link
Collaborator Author

FoamyGuy commented May 1, 2025

I have bisected this further and found that this is the most recent build that is behavior as expected:

adafruit-circuitpython-pyportal_titano-en_US-20250425-main-PR10292-e115623.uf2

and this is the first build where there behavior is broken (the next one in S3)

adafruit-circuitpython-pyportal_titano-en_US-20250426-main-PR10264-fa9b974.uf2

The PR from that build is #10264 which was selective collect for memory allocations, so this does further point towards something weird going on with the internal memory used by TPM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug displayio regression Things that used to work but don't any longer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant