[Bf-blender-cvs] [7cf5f4cc639] master: LineArt: Protecting bounding area links.

YimingWu noreply at git.blender.org
Mon Dec 27 07:54:37 CET 2021


Commit: 7cf5f4cc6395062645c6c1849a97c60cab2d09c7
Author: YimingWu
Date:   Mon Dec 27 14:33:39 2021 +0800
Branches: master
https://developer.blender.org/rB7cf5f4cc6395062645c6c1849a97c60cab2d09c7

LineArt: Protecting bounding area links.

In case they overflowed the bounding area maximum link count,
Protect the link array so it doesn't crash.

===================================================================

M	source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
M	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c

===================================================================

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);



More information about the Bf-blender-cvs mailing list