{"record":{"id":"fcf1ce90bc91fbfb","repo":"Yalantis/uCrop","slug":"load-off-failed-to-read-primitive-u-u-from-fi","errorCode":null,"errorMessage":"load_off(): Failed to read primitive %u/%u from file '%s'.","messagePattern":"load_off\\(\\): Failed to read primitive %u/%u from file '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59281,"sourceCode":"        }\n        (*this)(l,0) = (T)X; (*this)(l,1) = (T)Y; (*this)(l,2) = (T)Z;\n      }\n\n      // Read primitive data.\n      primitives.assign();\n      colors.assign();\n      bool stop_flag = false;\n      while (!stop_flag) {\n        float c0 = 0.7f, c1 = 0.7f, c2 = 0.7f;\n        unsigned int prim = 0, i0 = 0, i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0, i6 = 0, i7 = 0;\n        *line = 0;\n        if ((err = std::fscanf(nfile,\"%u\",&prim))!=1) stop_flag = true;\n        else {\n          ++nb_read;\n          switch (prim) {\n          case 1 : {\n            if ((err = std::fscanf(nfile,\"%u%255[^\\n] \",&i0,line._data))<2) {\n              cimg::warn(_cimg_instance\n                         \"load_off(): Failed to read primitive %u/%u from file '%s'.\",\n                         cimg_instance,\n                         nb_read,nb_primitives,filename?filename:\"(FILE*)\");\n\n              err = std::fscanf(nfile,\"%*[^\\n] \");\n            } else {\n              err = cimg_sscanf(line,\"%f%f%f\",&c0,&c1,&c2);\n              CImg<tf>::vector(i0).move_to(primitives);\n              CImg<tc>::vector((tc)(c0*255),(tc)(c1*255),(tc)(c2*255)).move_to(colors);\n            }\n          } break;\n          case 2 : {\n            if ((err = std::fscanf(nfile,\"%u%u%255[^\\n] \",&i0,&i1,line._data))<2) {\n              cimg::warn(_cimg_instance\n                         \"load_off(): Failed to read primitive %u/%u from file '%s'.\",\n                         cimg_instance,\n                         nb_read,nb_primitives,filename?filename:\"(FILE*)\");\n","sourceCodeStart":59263,"sourceCodeEnd":59299,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59263-L59299","documentation":"CImg::load_off() reads Wavefront OFF mesh files; each primitive line starts with a type code (1 = vertex, etc.). When the fscanf for a primitive or its payload fails, CImg warns with the primitive index (nb_read of nb_primitives), skips the malformed line, and continues reading, so the resulting mesh may be missing elements.","triggerScenarios":"Loading an OFF file whose primitive section has a truncated or malformed line — e.g. a vertex line without 3 coordinates or missing text after the type code — or a prematurely terminated file.","commonSituations":"OFF files exported by buggy/non-conforming tools; manual edits that break a line; file truncated during download; Windows/Mac line-ending or extra-token oddities the parser's format string rejects.","solutions":["Open the file at the reported primitive index and fix or remove the malformed line","Re-export the mesh from a known-good tool with standard OFF formatting","Check the file is complete (compare face/vertex counts in the header to actual lines)","Validate the OFF file with an external checker before loading","Treat missing primitives in the loaded mesh as a signal to abort rather than use the partial geometry"],"exampleFix":"// before\nCImg<float> points; CImgList<unsigned int> faces;\nprimitives.load_off(points, faces, \"mesh.off\"); // silently partial on malformed lines\n// after\nstd::ifstream in(\"mesh.off\");\nstd::string tok; in >> tok >> nv >> nf >> ne;\n// count non-empty lines after header; compare with nf before loading\nif (countPrimitiveLines(in) != nf) throw std::runtime_error(\"mesh.off is truncated\");","handlingStrategy":"validation","validationCode":"bool offFilePlausible(const char* path) {\n  std::ifstream in(path);\n  std::string h; unsigned nv, nf, ne;\n  if (!(in >> h >> nv >> nf >> ne) || h != \"OFF\") return false;\n  unsigned lines = 0; std::string s;\n  while (std::getline(in, s)) if (!s.empty()) ++lines;\n  return lines >= nv + nf;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate OFF headers against actual line counts before loading","Re-export meshes from conformant tools","Check transfer completeness (size/checksum) for mesh files","Treat missing primitives as a hard failure, not a partial load"],"tags":["cimg","file-io","off-mesh-format"],"backgroundTag":"file-parse-failed","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"}