{"record":{"id":"bf1ffaa684989194","repo":"Yalantis/uCrop","slug":"save-video-instance-list-is-empty","errorCode":null,"errorMessage":"save_video(): Instance list is empty.","messagePattern":"save_video\\(\\): Instance list is empty\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68579,"sourceCode":"            }\n        } else index = last_used_index;\n        cimg::mutex(9,0);\n\n        // Find empty slot for capturing video stream.\n        if (index<0) {\n          if (!filename)\n            throw CImgArgumentException(_cimglist_instance\n                                        \"save_video(): No already open video writer 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                                  \"save_video(): File '%s', no video writer slots available. \"\n                                  \"You have to release some of your previously opened videos.\",\n                                  cimglist_instance,filename);\n          if (is_empty())\n            throw CImgInstanceException(_cimglist_instance\n                                        \"save_video(): Instance list is empty.\",\n                                        cimglist_instance);\n          const unsigned int W = _data?_data[0]._width:0, H = _data?_data[0]._height:0;\n          if (!W || !H)\n            throw CImgInstanceException(_cimglist_instance\n                                        \"save_video(): Frame [0] is an empty image.\",\n                                        cimglist_instance);\n          const char\n            *const _codec = codec && *codec?codec:\"h264\",\n            codec0 = cimg::uppercase(_codec[0]),\n            codec1 = _codec[0]?cimg::uppercase(_codec[1]):0,\n            codec2 = _codec[1]?cimg::uppercase(_codec[2]):0,\n            codec3 = _codec[2]?cimg::uppercase(_codec[3]):0;\n          cimg::mutex(9);\n          writers[index] = new cv::VideoWriter(filename,_cimg_fourcc(codec0,codec1,codec2,codec3),fps,cv::Size(W,H));\n          if (!writers[index]->isOpened()) {\n            delete writers[index];\n            writers[index] = 0;","sourceCodeStart":68561,"sourceCodeEnd":68597,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68561-L68597","documentation":"Guard in CImgList<T>::save_video(): the frame list supplied for encoding is empty, so there are no images to write into the video stream; the writer checks list size before pushing frames to the OpenCV video writer.","triggerScenarios":"Calling save_video(filename,...) on a CImgList constructed empty, cleared, or whose frames were all moved out (e.g. via move_to) before the save.","commonSituations":"Capture loop that never appended frames (camera read failure) then attempted save; calling save_video after filtering/emptying the list.","solutions":["Check list.is_empty() (or size()>0) before calling save_video","Ensure the capture loop actually pushed frames into the list","Guard the save behind 'if (frames) frames.save_video(...)': skip or log otherwise"],"exampleFix":"// before\nframes.save_video(\"out.avi\", 25); // frames may be empty\n// after\nif (!frames.is_empty()) frames.save_video(\"out.avi\", 25);","handlingStrategy":"validation","validationCode":"// C++\nif (frames.is_empty()) return; // or log\n","typeGuard":"bool hasFrames(const CImgList<T>& l) { return !l.is_empty(); }","tryCatchPattern":"try { frames.save_video(fname, fps, codec); }\ncatch (CImgInstanceException& e) { log(\"no frames to encode\"); }","preventionTips":["Check size()/is_empty() before saving","Log capture failures so empty lists are noticed early","Only call save after the frame buffer is populated","Write unit tests covering empty-list saves"],"tags":["video","empty-data","opencv"],"backgroundTag":"empty-required-field","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"}