Fixed crashes when dialog dismissed while switched away.