Skip to content

picogame: validate the original object when the display cast yields NULL - #11306

Merged
tannewt merged 1 commit into
adafruit:mainfrom
MakerClassCZ:picogame-null-display-fix
Sep 4, 2026
Merged

tannewt merged 1 commit into
adafruit:mainfrom
MakerClassCZ:picogame-null-display-fix

Conversation

@lynt-smitka

Copy link
Copy Markdown

pg_get_display(), scene_resolve_target() and Display() pass the result of mp_obj_cast_to_native_base() to mp_arg_validate_type() when the argument is not a BusDisplay (eg. framebuffer). The cast returns MP_OBJ_NULL in that case and the error path dereferences it - on RP2350 a bus fault and a reset into safe mode instead of a TypeError.

Check for MP_OBJ_NULL and validate the object the caller passed, so the error names its real type (TypeError: display must be of type BusDisplay, not FramebufferDisplay). No change for valid arguments. Verified on a Fruit Jam.

pg_get_display(), scene_resolve_target() and Display() cast the display
argument to its busdisplay native base and, when the cast fails, passed the
result straight to mp_arg_validate_type(). mp_obj_cast_to_native_base()
returns MP_OBJ_NULL for anything that is not a BusDisplay (a
FramebufferDisplay, None, a pg.Framebuffer, an int), so the error path
called mp_obj_get_type(NULL) to name the offending type: on RP2040 that
read lands in the ROM's initial stack pointer and yields a TypeError with
a garbage type name, on RP2350 it is a bus fault at 0xF0000006 and the
board hard-faults into safe mode.

Check for MP_OBJ_NULL and validate the object the caller actually passed,
so the message names its real type:

    TypeError: display must be of type BusDisplay, not FramebufferDisplay

Verified on a Fruit Jam (RP2350): pg.invert()/pg.render()/pg.Scene() with
a FramebufferDisplay, None and an int all raise the TypeError above instead
of resetting the board; on the unpatched firmware the first call resets it
with SafeModeReason.HARD_FAULT.

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@tannewt
tannewt merged commit 3e8bd3e into adafruit:main Sep 4, 2026
44 of 45 checks 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.

2 participants