[Bf-blender-cvs] [2468bc8f1b4] temp-lineart-contained: LineArt: Add missing modifer and sanity checks to bake operator

Sebastian Parborg noreply at git.blender.org
Fri Mar 19 20:58:12 CET 2021


Commit: 2468bc8f1b4a17efc86a347369b9140d53b98f46
Author: Sebastian Parborg
Date:   Fri Mar 19 20:56:18 2021 +0100
Branches: temp-lineart-contained
https://developer.blender.org/rB2468bc8f1b4a17efc86a347369b9140d53b98f46

LineArt: Add missing modifer and sanity checks to bake operator

Previously we could crash because we would not check if the modifier in
question actually was a line art modifier. We also did not query if the
modifier was disabled.

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

M	source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c

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

diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c
index 1745551d6af..bd995a5940a 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c
@@ -29,6 +29,7 @@
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_gpencil.h"
+#include "BKE_gpencil_modifier.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
 
@@ -50,6 +51,24 @@
 
 #include "lineart_intern.h"
 
+static bool lineart_mod_is_disabled(GpencilModifierData *md)
+{
+  BLI_assert(md->type == eGpencilModifierType_Lineart);
+
+  const GpencilModifierTypeInfo *info = BKE_gpencil_modifier_get_info(md->type);
+
+  LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
+
+  /* Toggle on and off the baked flag as we are only interested in if something else is disabling
+   * it. We can assume that the guard function has already toggled this on for all modifiers that
+   * are sent here. */
+  lmd->flags &= (~LRT_GPENCIL_IS_BAKED);
+  bool disabled = info->isDisabled(md, 0);
+  lmd->flags |= LRT_GPENCIL_IS_BAKED;
+
+  return disabled;
+}
+
 static void clear_strokes(Object *ob, GpencilModifierData *md, int frame)
 {
   if (md->type != eGpencilModifierType_Lineart) {
@@ -74,6 +93,11 @@ static void clear_strokes(Object *ob, GpencilModifierData *md, int frame)
 
 static bool bake_strokes(Object *ob, Depsgraph *dg, GpencilModifierData *md, int frame)
 {
+  /* Modifier data sanity check. */
+  if (lineart_mod_is_disabled(md)) {
+    return false;
+  }
+
   LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
   bGPdata *gpd = ob->data;
 
@@ -148,11 +172,16 @@ static bool lineart_gpencil_bake_single_target(LineartBakeJob *bj, Object *ob, i
 
   if (bj->overwrite_frames) {
     LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) {
-      clear_strokes(ob, md, frame);
+      if (md->type == eGpencilModifierType_Lineart) {
+        clear_strokes(ob, md, frame);
+      }
     }
   }
 
   LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) {
+    if (md->type != eGpencilModifierType_Lineart) {
+      continue;
+    }
     if (bake_strokes(ob, bj->dg, md, frame)) {
       touched = true;
     }
@@ -254,6 +283,7 @@ static int lineart_gpencil_bake_common(bContext *C,
         LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) {
           if (md->type == eGpencilModifierType_Lineart) {
             BLI_linklist_prepend(&bj->objects, ob);
+            break;
           }
         }
       }



More information about the Bf-blender-cvs mailing list