kopia lustrzana https://github.com/pimoroni/pimoroni-pico
PicoVector: Fix ppp arc memory corruption.
rodzic
37083a6952
commit
94ee06e01b
|
@ -168,7 +168,7 @@ pp_poly_t* ppp_circle(ppp_circle_def d) {
|
||||||
pp_poly_t* ppp_arc(ppp_arc_def d) {
|
pp_poly_t* ppp_arc(ppp_arc_def d) {
|
||||||
pp_poly_t *poly = pp_poly_new();
|
pp_poly_t *poly = pp_poly_new();
|
||||||
pp_path_t *path = pp_poly_add_path(poly);
|
pp_path_t *path = pp_poly_add_path(poly);
|
||||||
pp_path_t *inner = (pp_path_t *)(d.s == 0.0f ? NULL : calloc(1, sizeof(pp_path_t)));
|
pp_path_t *inner = d.s != 0.0f ? pp_path_new() : NULL;
|
||||||
|
|
||||||
// no thickness, so add centre point to make pie shape
|
// no thickness, so add centre point to make pie shape
|
||||||
if(!inner) pp_path_add_point(path, (pp_point_t){d.x, d.y});
|
if(!inner) pp_path_add_point(path, (pp_point_t){d.x, d.y});
|
||||||
|
@ -185,7 +185,7 @@ pp_poly_t* ppp_arc(ppp_arc_def d) {
|
||||||
|
|
||||||
if(inner) { // append the inner path
|
if(inner) { // append the inner path
|
||||||
pp_path_add_points(path, inner->points, inner->count);
|
pp_path_add_points(path, inner->points, inner->count);
|
||||||
free(inner->points); free(inner);
|
pp_path_free(inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
return poly;
|
return poly;
|
||||||
|
|
|
@ -270,14 +270,26 @@ pp_poly_t *pp_poly_new() {
|
||||||
return poly;
|
return poly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pp_path_t *pp_path_new() {
|
||||||
|
pp_path_t *path = (pp_path_t *)PP_MALLOC(sizeof(pp_path_t));
|
||||||
|
memset(path, 0, sizeof(pp_path_t));
|
||||||
|
path->storage = 8;
|
||||||
|
path->points = (pp_point_t *)PP_MALLOC(sizeof(pp_point_t) * path->storage);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pp_path_free(pp_path_t *path) {
|
||||||
|
PP_FREE(path->points);
|
||||||
|
PP_FREE(path);
|
||||||
|
}
|
||||||
|
|
||||||
void pp_poly_free(pp_poly_t *poly) {
|
void pp_poly_free(pp_poly_t *poly) {
|
||||||
if(poly->paths) {
|
if(poly->paths) {
|
||||||
pp_path_t *path = poly->paths;
|
pp_path_t *path = poly->paths;
|
||||||
while(path) {
|
while(path) {
|
||||||
PP_FREE(path->points);
|
|
||||||
pp_path_t *free_path = path;
|
pp_path_t *free_path = path;
|
||||||
path = path->next;
|
path = path->next;
|
||||||
PP_FREE(free_path);
|
pp_path_free(free_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PP_FREE(poly);
|
PP_FREE(poly);
|
||||||
|
@ -302,10 +314,7 @@ int pp_poly_path_count(pp_poly_t *poly) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pp_path_t* pp_poly_add_path(pp_poly_t *poly) {
|
pp_path_t* pp_poly_add_path(pp_poly_t *poly) {
|
||||||
pp_path_t *path = (pp_path_t *)PP_MALLOC(sizeof(pp_path_t));
|
pp_path_t *path = pp_path_new();
|
||||||
memset(path, 0, sizeof(pp_path_t));
|
|
||||||
path->storage = 8;
|
|
||||||
path->points = (pp_point_t *)PP_MALLOC(sizeof(pp_point_t) * path->storage);
|
|
||||||
|
|
||||||
if(!poly->paths) {
|
if(!poly->paths) {
|
||||||
poly->paths = path;
|
poly->paths = path;
|
||||||
|
|
Ładowanie…
Reference in New Issue