[Bf-blender-cvs] [17eb5b3] master: Fix (unreported) memleak related to PBVH and looptri.

Bastien Montagne noreply at git.blender.org
Mon Jan 4 19:30:16 CET 2016


Commit: 17eb5b3af6ffeeb8d931ceaaf56fe82e40d8c084
Author: Bastien Montagne
Date:   Mon Jan 4 17:23:39 2016 +0100
Branches: master
https://developer.blender.org/rB17eb5b3af6ffeeb8d931ceaaf56fe82e40d8c084

Fix (unreported) memleak related to PBVH and looptri.

Looptri are not mesh data, they are allocated and built for PBVH only, and totally 'local' to it,
so duplicating like we do for verts & co leads to leaking memory.

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

M	source/blender/blenkernel/intern/pbvh.c

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

diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 16ba25e..699d70a 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -523,7 +523,12 @@ static void pbvh_build(PBVH *bvh, BB *cb, BBC *prim_bbc, int totprim)
 	build_sub(bvh, 0, cb, prim_bbc, 0, totprim);
 }
 
-/* Do a full rebuild with on Mesh data structure */
+/**
+ * Do a full rebuild with on Mesh data structure.
+ *
+ * \note Unlike mpoly/mloop/verts, looptri is **totally owned** by PBVH (which means it may rewrite it if needed,
+ *       see BKE_pbvh_apply_vertCos().
+ */
 void BKE_pbvh_build_mesh(
         PBVH *bvh, const MPoly *mpoly, const MLoop *mloop, MVert *verts,
         int totvert, struct CustomData *vdata,
@@ -1861,7 +1866,7 @@ void BKE_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3])
 			/* unneeded deformation -- duplicate verts/faces to avoid this */
 
 			pbvh->verts   = MEM_dupallocN(pbvh->verts);
-			pbvh->looptri = MEM_dupallocN(pbvh->looptri);
+			/* No need to dupalloc pbvh->looptri, this one is 'totally owned' by pbvh, it's never some mesh data. */
 
 			pbvh->deformed = true;
 		}




More information about the Bf-blender-cvs mailing list