{"record":{"id":"53b1156a087967d8","repo":"Yalantis/uCrop","slug":"load-camera-invalid-request-for-camera-u-no","errorCode":null,"errorMessage":"load_camera(): Invalid request for camera #%u (no more than 100 cameras can be managed simultaneously).","messagePattern":"load_camera\\(\\): Invalid request for camera #%u \\(no more than 100 cameras can be managed simultaneously\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":60079,"sourceCode":"      return res;\n    }\n\n#endif\n\n    //! Load image from a camera stream, using OpenCV.\n    /**\n       \\param index Index of the camera to capture images from (from 0 to 63).\n       \\param capture_width Width of the desired image ('0' stands for default value).\n       \\param capture_height Height of the desired image ('0' stands for default value).\n       \\param skip_frames Number of frames to skip before the capture.\n       \\param release_camera Tells if the camera resource must be released at the end of the method.\n    **/\n    CImg<T>& load_camera(const unsigned int camera_index=0,\n                         const unsigned int capture_width=0, const unsigned int capture_height=0,\n                         const unsigned int skip_frames=0, const bool release_camera=true) {\n#ifdef cimg_use_opencv\n      if (camera_index>=64)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_camera(): Invalid request for camera #%u \"\n                                    \"(no more than 100 cameras can be managed simultaneously).\",\n                                    cimg_instance,\n                                    camera_index);\n      static cv::VideoCapture *captures[64] = {};\n      static unsigned int captures_w[64], captures_h[64];\n      if (release_camera) {\n        cimg::mutex(9);\n        if (captures[camera_index]) captures[camera_index]->release();\n        delete captures[camera_index];\n        captures[camera_index] = 0;\n        captures_w[camera_index] = captures_h[camera_index] = 0;\n        cimg::mutex(9,0);\n        return *this;\n      }\n      if (!captures[camera_index]) {\n        cimg::mutex(9);\n        captures[camera_index] = new cv::VideoCapture(camera_index);","sourceCodeStart":60061,"sourceCodeEnd":60097,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L60061-L60097","documentation":"CImg manages a fixed static array of 64 cv::VideoCapture handles for load_camera(); requesting a camera_index >= 64 is rejected up-front with CImgArgumentException (note: the message text saying '100 cameras' is a stale comment — the real limit is 64).","triggerScenarios":"Calling load_camera(camera_index) with camera_index >= 64 (or any loop that enumerates cameras past index 63) when compiled with cimg_use_opencv.","commonSituations":"Probing /dev/video devices with a large range in a loop; passing a device ID from an external config that uses higher numbering; off-by-one assumptions about camera indexing.","solutions":["Keep camera_index within 0..63; map higher device numbers to a smaller logical index.","Release cameras (load_camera with release_camera=true, or stop captures) before opening more.","Use cv::VideoCapture directly for more than 64 concurrent cameras."],"exampleFix":"// before\nimg.load_camera(70); // throws\n// after\nif (cameraIndex < 64) img.load_camera(cameraIndex);\nelse throw std::runtime_error(\"camera index must be < 64\");","handlingStrategy":"validation","validationCode":"if (cameraIndex >= 64) throw std::invalid_argument(\"camera index must be < 64\");","typeGuard":null,"tryCatchPattern":"try { img.load_camera(cameraIndex); }\ncatch (CImgArgumentException& e) { /* clamp or remap index */ }","preventionTips":["Clamp/validate camera indices before opening","Reuse a small pool of camera slots and release captures when done","Do not blindly enumerate /dev/video* indices past 63"],"tags":["cimg","opencv","camera","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}