Skip to content

Commit 591058f

Browse files
committed
PicoVector: Store pointer to PP mem.
1 parent cfe8b3c commit 591058f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

micropython/modules/picovector/picovector.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef struct _ModPicoGraphics_obj_t {
2020

2121
typedef struct _VECTOR_obj_t {
2222
mp_obj_base_t base;
23+
void *mem;
2324
PicoVector *vector;
2425
} _VECTOR_obj_t;
2526

@@ -132,10 +133,10 @@ mp_obj_t RECTANGLE_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_k
132133
self->contour.points = m_new(pretty_poly::point_t<picovector_point_type>, 4);
133134
self->contour.count = 4;
134135

135-
self->contour.points[0] = {float(x), float(y)};
136-
self->contour.points[1] = {float(x + w), float(y)};
137-
self->contour.points[2] = {float(x + w), float(y + h)};
138-
self->contour.points[3] = {float(x), float(y + h)};
136+
self->contour.points[0] = {picovector_point_type(x), picovector_point_type(y)};
137+
self->contour.points[1] = {picovector_point_type(x + w), picovector_point_type(y)};
138+
self->contour.points[2] = {picovector_point_type(x + w), picovector_point_type(y + h)};
139+
self->contour.points[3] = {picovector_point_type(x), picovector_point_type(y + h)};
139140

140141
return self;
141142
}
@@ -286,10 +287,12 @@ mp_obj_t VECTOR_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
286287
_VECTOR_obj_t *self = m_new_obj(_VECTOR_obj_t);
287288
self->base.type = &VECTOR_type;
288289
ModPicoGraphics_obj_t *graphics = (ModPicoGraphics_obj_t *)MP_OBJ_TO_PTR(args[ARG_picographics].u_obj);
289-
290-
void *mem = m_tracked_calloc(PicoVector::pretty_poly_buffer_size(), sizeof(uint8_t));
291290

292-
self->vector = m_new_class(PicoVector, graphics->graphics, mem);
291+
// The PicoVector class calls `pretty_poly::init()` with the memory region
292+
// it does not store a pointer to this, so we need to store one ourselves
293+
self->mem = m_new(uint8_t, PicoVector::pretty_poly_buffer_size());
294+
295+
self->vector = m_new_class(PicoVector, graphics->graphics, self->mem);
293296

294297
return self;
295298
}
@@ -427,7 +430,7 @@ mp_obj_t VECTOR_draw(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
427430
if(!MP_OBJ_IS_TYPE(poly_obj, &POLYGON_type)) mp_raise_TypeError("draw: Polygon required.");
428431

429432
_POLYGON_obj_t *poly = MP_OBJ_TO_PTR2(poly_obj, _POLYGON_obj_t);
430-
contours.push_back(poly->contour);
433+
contours.emplace_back(poly->contour.points, poly->contour.count);
431434
}
432435

433436
self->vector->polygon(contours);

0 commit comments

Comments
 (0)