From patchwork Thu Sep 24 14:18:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9787 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6C638C3B5C for ; Thu, 24 Sep 2020 14:18:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AC1B762FE1; Thu, 24 Sep 2020 16:18:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="H2lwtoDQ"; dkim-atps=neutral Received: from mail.uajain.com (static.126.159.217.95.clients.your-server.de [95.217.159.126]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9475960362 for ; Thu, 24 Sep 2020 16:18:09 +0200 (CEST) From: Umang Jain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail; t=1600957089; bh=pk72IcqUtdO+zrVlVy6Cr0kkLrwfte2UPWojGY9lFA4=; h=From:To:Cc:Subject; b=H2lwtoDQxa0W45HbidLJRlwD2cX7e0ZSHKL5/A7Nv/ve3klczjClkyeJLFumYlX/Q TAOptIm7OdZt0pL7z/0u19XnfaynW47R7H2Ij9ug3yXsRhc/mSiMYS78LwskDXskt0 Ar2u4E2uqleQTjiVhIRRp4w8/IWv48NZTbyKEfOG5UX4YQxVvlysbqHsvaMnTihjvG RqaA5IerKDH2INxfpEswAd+iD7iqR1E6oxBiqmFuimwiSAMvOdA2ASQ7KOitql4qZL qEwPa7Ac2n1WQIqK9My6F9f0/Bs/L/ZaCmbJw/YbaqMjUq7Wfig221clNJyo0H/KYf UJPcCJtRdVq6Q== To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Sep 2020 19:48:02 +0530 Message-Id: <20200924141803.76422-1-email@uajain.com> Mime-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] simple-cam: Early return if no cameras found on the system X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Early return if no cameras are found on the system. Failing to do so, the codepath will segfault while trying to acquire a non-existent camera. Signed-off-by: Umang Jain Reviewed-by: Kieran Bingham --- simple-cam.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/simple-cam.cpp b/simple-cam.cpp index 3aa975e..d51000c 100644 --- a/simple-cam.cpp +++ b/simple-cam.cpp @@ -95,6 +95,13 @@ int main() CameraManager *cm = new CameraManager(); cm->start(); + if(!cm->cameras().size()) { + std::cout << "Please connect atleast one camera to the system." + << std::endl; + cm->stop(); + return -1; + } + /* * Just as a test, list all id's of the Camera registered in the * system. They are indexed by name by the CameraManager.