Fix double buffering sync code to deal with edge wrapping.