Fix T42138: division by zero in sapling addon

Note sapling code probably has other places where that kind of issues may happen,
would need a full recheck, but that's outside of scope of basic bugfix.

Patch by mangostaniko (Nikolaus Leopold) with minor changes, thanks!

Revision: D844
This commit is contained in:
Bastien Montagne 2014-10-29 10:08:15 +01:00
parent b714750bf0
commit 51b6f00666
Notes: blender-bot 2023-02-14 20:03:07 +01:00
Referenced by issue #42138, Sapling Add-On full of errors.
1 changed files with 3 additions and 3 deletions

View File

@ -196,7 +196,7 @@ def interpStem(stem,tVals,lPar,parRad):
# Loop through all the parametric values to be determined
for t in tVals:
if (t >= checkVal) and (t < 1.0):
scaledT = (t-checkVal)/(tVals[-1]-checkVal)
scaledT = (t - checkVal) / max(tVals[-1] - checkVal, 1e-6)
length = (numPoints-1)*t#scaledT
index = int(length)
if scaledT == 1.0:
@ -586,13 +586,13 @@ def fabricate_stems(addsplinetobone, addstem, baseSize, branches, childP, cu, cu
tempPos.rotate(rotMat)
tempPos.rotate(p.quat)
newPoint.handle_right = p.co + tempPos
if (storeN>= levels-1):
if (storeN >= levels):
# If this is the last level before leaves then we need to generate the child points differently
branchL = (length[n] + uniform(-lengthV[n], lengthV[n])) * (p.lengthPar - 0.6 * p.offset)
if leaves < 0:
childStems = False
else:
childStems = leaves * shapeRatio(leafDist, p.offset / p.lengthPar)
childStems = leaves * shapeRatio(leafDist, p.offset / max(p.lengthPar, 1e-6))
elif n == 1:
# If this is the first level of branching then upward attraction has no effect and a special formula is used to find branch length and the number of child stems
vertAtt = 0.0