Backport of the fix for the pinch-to-zoom division-by-zero issue