[Bf-blender-cvs] [6623efbe375] temp-gpencil-fill: GPencil: Try to solve corner case infinite loop

Antonio Vazquez noreply at git.blender.org
Sun Feb 7 13:26:35 CET 2021


Commit: 6623efbe37559d6e662a01af8a734415475ed0db
Author: Antonio Vazquez
Date:   Sun Feb 7 13:26:29 2021 +0100
Branches: temp-gpencil-fill
https://developer.blender.org/rB6623efbe37559d6e662a01af8a734415475ed0db

GPencil: Try to solve corner case infinite loop

In some cases the outline algoritm cannot detect pixels and the loop keeps running.

Now there is a check to avoid the same loop more than 3 times.

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

M	source/blender/editors/gpencil/gpencil_fill.c

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

diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 8ae98ec0fc2..9345707a5bb 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -1933,7 +1933,8 @@ static bool gpencil_do_frame_fill(tGPDfill *tgpf, const bool is_inverted)
     /* Clean borders to avoid infinite loops. */
     gpencil_set_borders(tgpf, false);
     WM_cursor_time(win, 50);
-
+    int totpoints_prv = 0;
+    int loop_limit = 0;
     while (totpoints > 0) {
       /* analyze outline */
       gpencil_get_outline_points(tgpf, (totpoints == 1) ? true : false);
@@ -1967,8 +1968,16 @@ static bool gpencil_do_frame_fill(tGPDfill *tgpf, const bool is_inverted)
 
       /* Limit very small areas. */
       if (totpoints < 3) {
-        totpoints = 0;
+        break;
+      }
+      /* Limit infinite loops is some corner cases. */
+      if (totpoints_prv == totpoints) {
+        loop_limit++;
+        if (loop_limit > 3) {
+          break;
+        }
       }
+      totpoints_prv = totpoints;
     }
 
     /* Delete temp image. */



More information about the Bf-blender-cvs mailing list