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.
This commit is contained in:
Tamito Kajiyama 2014-08-20 10:37:02 +09:00
parent 4b4ae8374f
commit eb8964fb7f
Notes: blender-bot 2023-02-14 10:12:56 +01:00
Referenced by commit f6b4b12961, Better fix for T41464: Material Boundary bug in Freestyle.
Referenced by issue #41464, Material Boundary bug in Freestyle
2 changed files with 16 additions and 11 deletions

View File

@ -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

View File

@ -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;
}