When setting the number of cavity samples to a high number blender could write out of bounds. This patch will harmonize the number of iterations in the same way how it is done during execution. Reviewed By: Clément Foucault Differential Revision: https://developer.blender.org/D7425