Skip to content

Commit

Permalink
PicoVector: Avoid MicroPython GC.
Browse files Browse the repository at this point in the history
Since we're not using tracked allocation, any memory we don't explicitly
hold a reference to will be assumed unused by MicroPython's GC.

Pass up the pp_nodes and pp_node_counts points (hackily) to fix this.
  • Loading branch information
Gadgetoid committed Nov 21, 2024
1 parent b184475 commit 896353a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libraries/pico_vector/pico_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ namespace pimoroni {
class PicoVector {
private:
af_text_metrics_t text_metrics;
// Hold copies of pretty-poly's pointers
// so MicroPython does not garbage collect them!
void *_pp_nodes;
void *_pp_node_counts;

public:
static PicoGraphics *graphics;
Expand All @@ -40,6 +44,8 @@ namespace pimoroni {
// TODO: Make these configurable?
// Tile buffer size, Max nodes per scanline
pp_init(16);
_pp_nodes = pp_nodes;
_pp_node_counts = pp_node_counts;

pp_tile_callback(PicoVector::tile_callback);

Expand Down
5 changes: 5 additions & 0 deletions libraries/pico_vector/pretty-poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ extern pp_tile_callback_t _pp_tile_callback;
extern pp_antialias_t _pp_antialias;
extern pp_mat3_t *_pp_transform;

// Our parent scope might want to hold a pointer to these
// ie: MicroPython to avoid garbage collection
extern int32_t *pp_nodes;
extern uint32_t *pp_node_counts;

void pp_clip(int32_t x, int32_t y, int32_t w, int32_t h);
void pp_tile_callback(pp_tile_callback_t callback);
void pp_antialias(pp_antialias_t antialias);
Expand Down

0 comments on commit 896353a

Please sign in to comment.