[Bf-blender-cvs] [cd349dc4023] master: LineArt: Use thread safe bound box.

YimingWu noreply at git.blender.org
Tue May 10 16:05:51 CEST 2022


Commit: cd349dc4023aa1e6b4728ae6804ae36a5e170758
Author: YimingWu
Date:   Tue May 10 14:41:35 2022 +0800
Branches: master
https://developer.blender.org/rBcd349dc4023aa1e6b4728ae6804ae36a5e170758

LineArt: Use thread safe bound box.

The old method is not thread safe, which will lead to minor
memory leaks. This patch fixed that.

Reviewed By: Sebastian Parborg (zeddb)

Differential Revision: https://developer.blender.org/D14904

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

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

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

diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index dbe2ae0b890..b09bb15ce81 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -2358,18 +2358,21 @@ static void lineart_geometry_load_assign_thread(LineartObjectLoadTaskInfo *olti_
 static bool lineart_geometry_check_visible(double (*model_view_proj)[4],
                                            double shift_x,
                                            double shift_y,
-                                           Object *use_ob)
+                                           Mesh *use_mesh)
 {
-  const BoundBox *bb = BKE_object_boundbox_get(use_ob);
-  if (!bb) {
-    /* For lights and empty stuff there will be no bbox. */
+  if (!use_mesh) {
     return false;
   }
+  float mesh_min[3], mesh_max[3];
+  INIT_MINMAX(mesh_min, mesh_max);
+  BKE_mesh_minmax(use_mesh, mesh_min, mesh_max);
+  BoundBox bb = {0};
+  BKE_boundbox_init_from_minmax(&bb, mesh_min, mesh_max);
 
   double co[8][4];
   double tmp[3];
   for (int i = 0; i < 8; i++) {
-    copy_v3db_v3fl(co[i], bb->vec[i]);
+    copy_v3db_v3fl(co[i], bb.vec[i]);
     copy_v3_v3_db(tmp, co[i]);
     mul_v4_m4v3_db(co[i], model_view_proj, tmp);
     co[i][0] -= shift_x * 2 * co[i][3];
@@ -2481,13 +2484,6 @@ static void lineart_main_load_geometries(
       continue;
     }
 
-    if (!lineart_geometry_check_visible(obi->model_view_proj, rb->shift_x, rb->shift_y, use_ob)) {
-      if (G.debug_value == 4000) {
-        bound_box_discard_count++;
-      }
-      continue;
-    }
-
     if (use_ob->type == OB_MESH) {
       use_mesh = BKE_object_get_evaluated_mesh(use_ob);
     }
@@ -2506,6 +2502,17 @@ static void lineart_main_load_geometries(
       continue;
     }
 
+    if (!lineart_geometry_check_visible(
+            obi->model_view_proj, rb->shift_x, rb->shift_y, use_mesh)) {
+      if (ob->type != OB_MESH) {
+        BKE_id_free(NULL, use_mesh);
+      }
+      if (G.debug_value == 4000) {
+        bound_box_discard_count++;
+      }
+      continue;
+    }
+
     if (ob->type != OB_MESH) {
       obi->free_use_mesh = true;
     }



More information about the Bf-blender-cvs mailing list