band.AddBetweenSegments can return zero on error
|Opened on:||Saturday, November 21, 2015 - 19:26|
|Last modified:||Tuesday, July 31, 2018 - 20:52|
There's an inconsistency in how band.AddBetweenSegments handles errors. Recipes which generate random bands, such as GAB family of recipes, may suffer rare crashes as a result.
A call like
bIdx= band.AddBetweenSegments ( 21, -21 )
"throws" an error with a "bad argument #2" message. Unless the pcall function is used to call AddBetweenSegments, the error terminates the recipe.
However, a call like
bIdx = band.AddBetweenSegments ( 21, 21 )
does not issue an error, but does return zero for the band index (bIdx = 0).
It would be more consistent to throw an error in this case. As far as I know, the case of segment index 1 == segment index 2 is the *only* one which gets a zero return code instead of a thrown error from this function. In general, the foldit Lua functions throw errors instead of setting return codes.
Many recipes generate random bands. Once in a while, these recipes will draw the same number twice. The band.AddBetweenSegments won't seem to fail, but functions like band.SetStrength will crash, if passed band index zero. The solution is to either check for band index 1 == band index2 or check for a zero return code. A careful recipe "cook" will do both.