Skip to content

Commit

Permalink
PicoGraphics: Check for out of range layers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Dec 3, 2024
1 parent 2e38a72 commit 01d8aa7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion micropython/modules/picographics/picographics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef struct _ModPicoGraphics_obj_t {
void *fontdata;
_PimoroniI2C_obj_t *i2c;
bool blocking = true;
//mp_obj_t scanline_callback; // Not really feasible in MicroPython
uint8_t layers;
} ModPicoGraphics_obj_t;

bool get_display_settings(PicoGraphicsDisplay display, int &width, int &height, int &rotate, int &pen_type, PicoGraphicsBusType &bus_type) {
Expand Down Expand Up @@ -477,6 +477,7 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size

//self->scanline_callback = mp_const_none;

self->layers = layers;
self->spritedata = nullptr;

// Clear the buffer
Expand Down Expand Up @@ -807,6 +808,10 @@ mp_obj_t ModPicoGraphics_set_pen(mp_obj_t self_in, mp_obj_t pen) {
mp_obj_t ModPicoGraphics_set_layer(mp_obj_t self_in, mp_obj_t layer) {
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);

if (mp_obj_get_int(layer) >= self->layers) {
mp_raise_ValueError("set_layer: layer out of range!");
}

self->graphics->set_layer(mp_obj_get_int(layer));

return mp_const_none;
Expand Down
4 changes: 4 additions & 0 deletions micropython/modules/picovector/picovector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ typedef struct _ModPicoGraphics_obj_t {
mp_obj_base_t base;
PicoGraphics *graphics;
DisplayDriver *display;
void *spritedata;
void *buffer;
void *fontdata;
void *i2c;
bool blocking = true;
} ModPicoGraphics_obj_t;

typedef struct _VECTOR_obj_t {
Expand Down

0 comments on commit 01d8aa7

Please sign in to comment.