Fix the crash while replacing the surface