Fixed boundary-related bug in 3D swapping.