[Bf-blender-cvs] [eb8964f] master: Fix T41464: Material Boundary bug in Freestyle.

Tamito Kajiyama noreply at git.blender.org
Wed Aug 20 04:13:45 CEST 2014


Commit: eb8964fb7f19463acdf441592a29dbfc1ff3ab29
Author: Tamito Kajiyama
Date:   Wed Aug 20 10:37:02 2014 +0900
Branches: master
https://developer.blender.org/rBeb8964fb7f19463acdf441592a29dbfc1ff3ab29

Fix T41464: Material Boundary bug in Freestyle.

The reported issue was caused by an old bug combined with another bug
introduced by recent Freestyle Python API updates.

The old bug was that a mutable reference to CurvePoint was treated as if
it were immutable.  Iteration over CurvePoint objects is implemented by
the C++ CurvePointIterator class, whose dereference method
CurvePointIterator::operator*() returns a reference to a mutable data
member (probably originally intended for better performance).  Hence the
returned reference may vary upon iteration over different CurvePoints.
This implementation detail was overlooked and the returned reference was
treated as immutable (which is the case in fact for other Interface0D
subclasses except for CurvePoint).  This bug was surprisingly old as it
existed before the beginning of Freestyle integration into Blender.

The other bug was in the MaterialBoundaryUP0D predicate class that was
not properly handling the end of iteration.  It is noted that when the
iter() and next() built-in functions are applied to Interface0DIterator,
it is no longer possible to reliably check the end of iteration by the
.is_end property of the iterator.  Namely, the .is_end property works as
expected only when iteration is carried out in combination with the
conventional .increment() and .decrement() methods of the iterator.  For
this reason the commit rBb408d8af31c9 was partly reverted to recover the
previous definition of MaterialBoundaryUP0D.

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

M	release/scripts/freestyle/modules/parameter_editor.py
M	source/blender/freestyle/intern/python/BPy_Convert.cpp

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

diff --git a/release/scripts/freestyle/modules/parameter_editor.py b/release/scripts/freestyle/modules/parameter_editor.py
index 6de53c6..6ab4184 100644
--- a/release/scripts/freestyle/modules/parameter_editor.py
+++ b/release/scripts/freestyle/modules/parameter_editor.py
@@ -814,17 +814,17 @@ class FaceMarkOneUP1D(UnaryPredicate1D):
 
 class MaterialBoundaryUP0D(UnaryPredicate0D):
     def __call__(self, it):
-        if (it.is_begin or it.is_end):
+        if it.is_begin:
             return False
-        else:
-            it.decrement()
-            prev = it.object
-            svert = next(it)
-            succ = next(it)
-
-        fe = svert.get_fedge(prev)
+        it_prev = Interface0DIterator(it)
+        it_prev.decrement()
+        v = it.object
+        it.increment()
+        if it.is_end:
+            return False
+        fe = v.get_fedge(it_prev.object)
         idx1 = fe.material_index if fe.is_smooth else fe.material_index_left
-        fe = svert.get_fedge(succ)
+        fe = v.get_fedge(it.object)
         idx2 = fe.material_index if fe.is_smooth else fe.material_index_left
         return idx1 != idx2
 
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp
index 78c3599..dbd836b 100644
--- a/source/blender/freestyle/intern/python/BPy_Convert.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp
@@ -387,9 +387,14 @@ PyObject *BPy_IntegrationType_from_IntegrationType(IntegrationType i)
 PyObject *BPy_CurvePoint_from_CurvePoint(CurvePoint& cp)
 {
 	PyObject *py_cp = CurvePoint_Type.tp_new(&CurvePoint_Type, 0, 0);
-	((BPy_CurvePoint *) py_cp)->cp = &cp;
+	// CurvePointIterator::operator*() returns a reference of a class data
+	// member whose value is mutable upon iteration over different CurvePoints.
+	// It is likely that such a mutable reference is passed to this function,
+	// so that a new allocated CurvePoint instance is created here to avoid
+	// nasty bugs (cf. T41464).
+	((BPy_CurvePoint *) py_cp)->cp = new CurvePoint(cp);
 	((BPy_CurvePoint *) py_cp)->py_if0D.if0D = ((BPy_CurvePoint *)py_cp)->cp;
-	((BPy_CurvePoint *) py_cp)->py_if0D.borrowed = true;
+	((BPy_CurvePoint *) py_cp)->py_if0D.borrowed = false;
 	return py_cp;
 }




More information about the Bf-blender-cvs mailing list