Yalantis/uCrop · warning

load_off(): Only %u/%u primitives read from file

Error message

load_off(): Only %u/%u primitives read from file '%s'.

What it means

load_off() failed to parse one primitive (face/polygon) while reading an OFF mesh file: the vertex count for that primitive was unexpected or the line could not be parsed. It warns with cimg::warn, skips the line (%[^\n] scan) and continues, so the mesh loads with one fewer primitive than declared.

Solutions

  1. Pre-process the OFF file to triangulate faces (e.g. with MeshLab or a script) so every face line has exactly 3 vertex indices.
  2. Fix malformed face lines (ensure each face starts with a valid count N followed by N integer indices in range).
  3. Validate the OFF structure (counts vs actual lines) before loading; reject or repair non-conforming files.
  4. If the source mesh is fine but CImg's parser is too limited, convert to another format (e.g. via meshlab/assimp) and use the corresponding loader.

Example fix

# repair step: triangulate the OFF before loading
meshlabserver -i model.off -o model_tri.off -m wt
# then
mesh.load_off("model_tri.off");
Defensive patterns

Strategy: validation

Validate before calling

// validate OFF face lines parse as 'N i0 ... i{N-1}' before loading
for (auto& line : faceLines) if (!isValidFaceLine(line)) repairOrReject(line);

Try / catch

try { mesh.load_off(path, colors, prims); } catch (CImgIOException& e) { /* re-export mesh */ }

Prevention

When it happens

Trigger: Loading a malformed OFF file whose face lines do not match 'N v1 v2 ... vN' with a supported N (CImg's parser handles triangles and quads specially; larger polygons or malformed counts hit the default branch of the parse switch).

Common situations: OFF files with polygons of more vertices than the parser handles; files with negative or out-of-range vertex indices; non-integer tokens on face lines; hand-edited or tool-exported OFF with trailing garbage on face lines.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/8f0b974a53a56b4b. Report an issue: GitHub.

Appendix: source

Thrown at ucrop/src/main/jni/CImg.h:59402

          case 8 : {
            if ((err = std::fscanf(nfile,"%u%u%u%u%u%u%u%u%255[^\n] ",&i0,&i1,&i2,&i3,&i4,&i5,&i6,&i7,line._data))<7) {
              cimg::warn(_cimg_instance
                         "load_off(): Failed to read primitive %u/%u from file '%s'.",
                         cimg_instance,
                         nb_read,nb_primitives,filename?filename:"(FILE*)");

              err = std::fscanf(nfile,"%*[^\n] ");
            } else {
              err = cimg_sscanf(line,"%f%f%f",&c0,&c1,&c2);
              CImg<tf>::vector(i0,i3,i2,i1).move_to(primitives);
              CImg<tf>::vector(i0,i5,i4,i3).move_to(primitives);
              CImg<tf>::vector(i0,i7,i6,i5).move_to(primitives);
              colors.insert(3,CImg<tc>::vector((tc)(c0*255),(tc)(c1*255),(tc)(c2*255)));
              ++(++nb_primitives);
            }
          } break;
          default :
            cimg::warn(_cimg_instance
                       "load_off(): Failed to read primitive %u/%u (%u vertices) from file '%s'.",
                       cimg_instance,
                       nb_read,nb_primitives,prim,filename?filename:"(FILE*)");

            err = std::fscanf(nfile,"%*[^\n] ");
          }
        }
      }
      if (!file) cimg::fclose(nfile);
      if (primitives._width!=nb_primitives)
        cimg::warn(_cimg_instance
                   "load_off(): Only %u/%u primitives read from file '%s'.",
                   cimg_instance,
                   primitives._width,nb_primitives,filename?filename:"(FILE*)");
      return *this;
    }

    //! Load image sequence from a video file, using OpenCV library.

View on GitHub (pinned to f788b534b4)