From 7cf5f4cc6395062645c6c1849a97c60cab2d09c7 Mon Sep 17 00:00:00 2001 From: YimingWu Date: Mon, 27 Dec 2021 14:33:39 +0800 Subject: LineArt: Protecting bounding area links. In case they overflowed the bounding area maximum link count, Protect the link array so it doesn't crash. --- .../blender/gpencil_modifiers/intern/lineart/MOD_lineart.h | 8 ++++---- .../blender/gpencil_modifiers/intern/lineart/lineart_cpu.c | 13 ++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'source/blender/gpencil_modifiers/intern/lineart') diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h index 2ef72da03fd..dadeebeff0a 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h +++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h @@ -450,10 +450,10 @@ typedef struct LineartBoundingArea { ListBase up; ListBase bp; - int16_t triangle_count; - int16_t max_triangle_count; - int16_t line_count; - int16_t max_line_count; + uint16_t triangle_count; + uint16_t max_triangle_count; + uint16_t line_count; + uint16_t max_line_count; /* Use array for speeding up multiple accesses. */ struct LineartTriangle **linked_triangles; diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c index f0ab7f3ee31..9241d256db0 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c @@ -327,7 +327,12 @@ BLI_INLINE bool lineart_occlusion_is_adjacent_intersection(LineartEdge *e, Linea static void lineart_bounding_area_triangle_add(LineartRenderBuffer *rb, LineartBoundingArea *ba, LineartTriangle *tri) -{ +{ /* In case of too many triangles concentrating in one point, do not add anymore, these triangles + * will be either narrower than a single pixel, or will still be added into the list of other + * less dense areas. */ + if (ba->triangle_count >= 65535) { + return; + } if (ba->triangle_count >= ba->max_triangle_count) { LineartTriangle **new_array = lineart_mem_acquire( &rb->render_data_pool, sizeof(LineartTriangle *) * ba->max_triangle_count * 2); @@ -343,6 +348,12 @@ static void lineart_bounding_area_line_add(LineartRenderBuffer *rb, LineartBoundingArea *ba, LineartEdge *e) { + /* In case of too many lines concentrating in one point, do not add anymore, these lines will + * be either shorter than a single pixel, or will still be added into the list of other less + * dense areas. */ + if (ba->line_count >= 65535) { + return; + } if (ba->line_count >= ba->max_line_count) { LineartEdge **new_array = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartEdge *) * ba->max_line_count * 2); -- cgit v1.2.3