Exception on closing inactive UI causes issues (#14651)
Added proposed fix

Change-Id: I88085546c2bf47f1e0952d64efadfc40bac12987