Null pointer check when closing the portal.