Did you find a solution for this?
I looked over your code and to be honest I can’t see anything wrong with it.
I’ve found that at time PHP can have strange problems with conditions, I would try changing the while to
while( have_rows( 'photos') && ($imageCounter < $maxNoImages) ):
and maybe isolating that the second part will correct the error.