Oops. Defining max() the wrong way round was breaking rect select.