Fix possible crashes and save gradient editor state