Added check for mesh == null.