Fix crash when deleting viewer