{"record":{"id":"d6feb91ccea5f276","repo":"Yalantis/uCrop","slug":"load-video-no-already-open-video-reader-found","errorCode":null,"errorMessage":"load_video(): No already open video reader found. You must specify a non-(null) filename argument for the first call.","messagePattern":"load_video\\(\\): No already open video reader found\\. You must specify a non-\\(null\\) filename argument for the first call\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":67364,"sourceCode":"          if (last_used_index==index) last_used_index = -1;\n          index = -1;\n          cimg::mutex(9,0);\n        } else\n          if (filename)\n            cimg::warn(_cimglist_instance\n                       \"load_video() : File '%s', no opened video stream associated with filename found.\",\n                       cimglist_instance,filename);\n          else\n            cimg::warn(_cimglist_instance\n                       \"load_video() : No opened video stream found.\",\n                       cimglist_instance,filename);\n        if (!step_frame) return *this;\n      }\n\n      // Find empty slot for capturing video stream.\n      if (index<0) {\n        if (!filename)\n          throw CImgArgumentException(_cimglist_instance\n                                      \"load_video(): No already open video reader found. You must specify a \"\n                                      \"non-(null) filename argument for the first call.\",\n                                      cimglist_instance);\n        else { cimg::mutex(9); cimglist_for(filenames,l) if (!filenames[l]) { index = l; break; } cimg::mutex(9,0); }\n        if (index<0)\n          throw CImgIOException(_cimglist_instance\n                                \"load_video(): File '%s', no video reader slots available. \"\n                                \"You have to release some of your previously opened videos.\",\n                                cimglist_instance,filename);\n        cimg::mutex(9);\n        captures[index] = new cv::VideoCapture(filename);\n        positions[index] = 0;\n        if (!captures[index]->isOpened()) {\n          delete captures[index];\n          captures[index] = 0;\n          cimg::mutex(9,0);\n          cimg::fclose(cimg::fopen(filename,\"rb\")); // Check file availability\n          throw CImgIOException(_cimglist_instance","sourceCodeStart":67346,"sourceCodeEnd":67382,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L67346-L67382","documentation":"In the OpenCV-backed load_video(), passing filename=nullptr with index<0 means 'continue with the already open video reader'. If no such reader exists (this is the first call), CImg throws this CImgArgumentException because there is nothing to continue from. The API contract requires a non-null filename on the first call to open a capture slot.","triggerScenarios":"Calling CImgList::load_video(nullptr, ..., index) (or relying on the null-filename continuation mode) before any successful call opened a video, so the internal captures[] array has no active reader.","commonSituations":"Incremental frame-pulling code that calls load_video(nullptr) on each iteration but whose first call failed (e.g. the file was missing), leaving no open reader for subsequent null-filename calls.","solutions":["Pass a valid, existing video filename on the first load_video call to open a reader slot.","Ensure the initial open call succeeded before switching to null-filename continuation calls.","Reuse the same CImgList instance across calls so its internal captures[] state (and last_used_index) is preserved."],"exampleFix":"// before\nCImgList<unsigned char> frames;\nframes.load_video(nullptr, 0, ~0U, 1, -1); // no reader open -> throws\n\n// after\nCImgList<unsigned char> frames;\nframes.load_video(\"clip.mp4\", 0, ~0U, 1, -1); // opens reader first\n// subsequent calls may use nullptr to continue with the open reader\nframes.load_video(nullptr, 5, ~0U, 1, -1);","handlingStrategy":"validation","validationCode":"// track whether a reader was opened\nbool readerOpened = false;\n// first call must pass a real filename:\nif (!readerOpened && filename == nullptr) {\n  // refuse to call with nullptr before the first successful open\n}","typeGuard":"bool canLoadContinuation(const char* filename, bool readerOpen) {\n  return filename != nullptr || readerOpen;\n}","tryCatchPattern":"try {\n  list.load_video(filename, first, last, step, index);\n} catch (CImgArgumentException&) {\n  // no open reader: open with a real filename first\n  list.load_video(realFile, 0, ~0U, 1, -1);\n}","preventionTips":["Always pass a valid filename on the first load_video call.","Keep the same CImgList instance alive for continuation calls so reader state persists.","Only switch to nullptr-filename calls after a successful open."],"tags":["cimg","opencv","video","null-argument","api-usage"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}