Yalantis/uCrop · error · CImgInstanceException
dijkstra(): Instance is not a graph adjacency matrix.
Error message
dijkstra(): Instance is not a graph adjacency matrix.
What it means
get_dijkstra() interprets the instance as a square graph adjacency matrix, requiring _width==_height and _depth==_spectrum==1. Any other shape cannot be an adjacency matrix, so CImgInstanceException is thrown.
Source
Thrown at ucrop/src/main/jni/CImg.h:33932
\param starting_node Index of the starting node.
\param ending_node Index of the 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.
\note image instance corresponds to the adjacency matrix of the graph.
**/
template<typename t>
CImg<T>& dijkstra(const unsigned int starting_node, const unsigned int ending_node,
CImg<t>& previous_node) {
return get_dijkstra(starting_node,ending_node,previous_node).move_to(*this);
}
//! Return minimal path in a graph, using the Dijkstra algorithm \newinstance.
template<typename t>
CImg<T> get_dijkstra(const unsigned int starting_node, const unsigned int ending_node,
CImg<t>& previous_node) const {
if (_width!=_height || _depth!=1 || _spectrum!=1)
throw CImgInstanceException(_cimg_instance
"dijkstra(): Instance is not a graph adjacency matrix.",
cimg_instance);
return dijkstra(*this,_width,starting_node,ending_node,previous_node);
}
//! Return minimal path in a graph, using the Dijkstra algorithm.
CImg<T>& dijkstra(const unsigned int starting_node, const unsigned int ending_node=~0U) {
return get_dijkstra(starting_node,ending_node).move_to(*this);
}
//! Return minimal path in a graph, using the Dijkstra algorithm \newinstance.
CImg<Tfloat> get_dijkstra(const unsigned int starting_node, const unsigned int ending_node=~0U) const {
CImg<uintT> foo;
return get_dijkstra(starting_node,ending_node,foo);
}
//! Return an image containing the character codes of specified string.View on GitHub (pinned to f788b534b4)
Solutions
- Build/convert the graph into an NxN single-channel adjacency matrix (width==height, depth=1, spectrum=1)
- Extract the relevant channel/slice if your graph is stored multi-channel
- Use the static dijkstra(distance_fn, nb_nodes, ...) overload with a custom distance functor when the graph isn't matrix-representable
Example fix
// before weights.get_dijkstra(s, e, prev); // weights is 100x50 // after CImg<float> adj(100, 100, 1, 1, 0); // build NxN adjacency // ... fill adj ... adj.get_dijkstra(s, e, prev);
Defensive patterns
Strategy: validation
Validate before calling
if (g.width() == g.height() && g.depth() == 1 && g.spectrum() == 1) { g.get_dijkstra(s, e, prev); } else { /* build NxN adjacency first */ } Type guard
bool isAdjacencyMatrix(const CImg<T>& m) { return m.width() == m.height() && m.depth() == 1 && m.spectrum() == 1; } Try / catch
try { g.get_dijkstra(s, e, prev); } catch (CImgInstanceException& e) { /* convert edge list to adjacency matrix and retry */ } Prevention
- Represent graphs as NxN single-channel adjacency matrices for CImg
- Convert edge lists explicitly before graph algorithms
- Validate start/end node bounds too (see dijkstra index error)
When it happens
Trigger: Calling get_dijkstra(start, end, previous_node) on a non-square image, a 3D volume, or a multi-channel image instead of an NxN single-channel weighted adjacency matrix.
Common situations: Passing an edge list image instead of an adjacency matrix; passing a rectangular weight map; forgetting to flatten a multi-channel graph representation.
Understand the failure class
Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.
Related errors
- CImg<%s>::dijkstra(): Specified index of starting node %u is
- SVD(): Instance has invalid dimensions (depth or channels di
- project_matrix(): Instance image is not a matrix.
- cimg::SDL3_attr(): %s
- cimg::mod(): Specified modulo value is 0.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/0b09ccee84a81af7.
Report an issue: GitHub.