Skip to content

Hard Fault from np.array #10714

@FoamyGuy

Description

@FoamyGuy
Adafruit CircuitPython 10.0.3 on 2025-10-17; Adafruit MagTag with ESP32S2

With this reproducer code:

from displayio import Bitmap
import ulab.numpy as np

class IterableBitmap:
    def __init__(self, bitmap):
        self._bitmap = bitmap
        self.index = 0

    def __iter__(self):
        return self  # Object itself is the iterator

    def __next__(self):
        if self.index >= self._bitmap.width * self._bitmap.height:
            raise StopIteration
        item = self._bitmap[self.index]
        self.index += 1
        return item


source_bitmap = Bitmap(10,10, 10)
source_bitmap.fill(1)

iter_bmp = IterableBitmap(source_bitmap)

# un-commenting this iteration loop causes it not to hard fault
# for _ in iter_bmp:
#     print(_)

arr = np.array(iter_bmp, dtype=np.float)
print("after arr create")

while True:
    pass

The MagTag hard faults with "memory access or instruction error".

Interestingly if the print iteration loop before np.array() is un-commented then it no longer hard faults. But does not seem to create an array of the expected size either, but that is a separate, less severe issue.

Before I created this minimal reproducer I was trying to use similar code with an actual image and the MagTag hard crashed, but did not reset itself back into safe mode it just stayed crashed/disconnected from PC. I had to recover with manual safe mode access. This smaller reproducer seems to be able to get itself back into safe mode automatically though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions