Yalantis/uCrop · error · CImgArgumentException

CImg<%s>::dijkstra(): Specified index of starting node %u is

Error message

CImg<%s>::dijkstra(): Specified index of starting node %u is higher than number of nodes %u.

What it means

CImg's static dijkstra() computes shortest paths over nb_nodes nodes indexed 0..nb_nodes-1. If starting_node >= nb_nodes the starting index is out of range and CImgArgumentException is thrown before any traversal.

Source

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

    }

    //! Compute minimal path in a graph, using the Dijkstra algorithm.
    /**
       \param distance An object having operator()(unsigned int i, unsigned int j) which returns distance
         between two nodes (i,j).
       \param nb_nodes Number of graph nodes.
       \param starting_node Index of the starting node.
       \param ending_node Index of the ending node (set to ~0U to ignore ending node).
       \param previous_node Array that gives the previous node index in the path to the starting node
         (optional parameter).
       \return Array of distances of each node to the starting node.
    **/
    template<typename tf, typename t>
    static CImg<T> dijkstra(const tf& distance, const unsigned int nb_nodes,
                            const unsigned int starting_node, const unsigned int ending_node,
                            CImg<t>& previous_node) {
      if (starting_node>=nb_nodes)
        throw CImgArgumentException("CImg<%s>::dijkstra(): Specified index of starting node %u is higher "
                                    "than number of nodes %u.",
                                    pixel_type(),starting_node,nb_nodes);
      CImg<T> dist(1,nb_nodes,1,1,cimg::type<T>::max());
      dist(starting_node) = 0;
      previous_node.assign(1,nb_nodes,1,1,(t)-1);
      previous_node(starting_node) = (t)starting_node;
      CImg<uintT> Q(nb_nodes);
      cimg_forX(Q,u) Q(u) = (unsigned int)u;
      cimg::swap(Q(starting_node),Q(0));
      unsigned int sizeQ = nb_nodes;
      while (sizeQ) {
        // Update neighbors from minimal vertex.
        const unsigned int umin = Q(0);
        if (umin==ending_node) sizeQ = 0;
        else {
          const T dmin = dist(umin);
          const T infty = cimg::type<T>::max();
          for (unsigned int q = 1; q<sizeQ; ++q) {

View on GitHub (pinned to f788b534b4)

Solutions

  1. Validate starting_node < nb_nodes (and ideally ending_node < nb_nodes) before calling
  2. Convert 1-based ids to 0-based: call with starting_node - 1 if your ids start at 1
  3. Check the source of nb_nodes matches the graph actually being traversed

Example fix

// before
unsigned start = nodeId; // 1-based, can be == nb_nodes
CImg<float> path = CImg<float>::dijkstra(dist, n, start, end, prev);
// after
if (nodeId >= 1 && nodeId <= n) {
  CImg<float> path = CImg<float>::dijkstra(dist, n, nodeId - 1, end, prev);
}
Defensive patterns

Strategy: validation

Validate before calling

if (starting_node >= nb_nodes || ending_node >= nb_nodes) throw std::out_of_range("node index must be < nb_nodes");

Type guard

bool isValidNode(unsigned node, unsigned nb_nodes) { return node < nb_nodes; }

Try / catch

try { CImg<T> path = CImg<T>::dijkstra(dist, n, s, e, prev); } catch (CImgArgumentException& e) { /* clamp/reject node id */ }

Prevention

When it happens

Trigger: Calling CImg<T>::dijkstra(distance, nb_nodes, starting_node, ending_node, previous_node) with starting_node >= nb_nodes — typically an off-by-one (passing nb_nodes itself) or an unvalidated node id.

Common situations: 1-based node ids passed to the 0-based API; node id read from user input/file without bounds check; nb_nodes computed from a smaller graph than the ids refer to.

Related errors


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