{"record":{"id":"c738942f9ca919ba","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-array","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: %s: Array brackets used on non-vector variable '%s', in expression '%s'.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Array brackets used on non-vector variable '(.+?)', in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":19876,"sourceCode":"              if (!imglist) _cimg_mp_return(0);\n              pos = scalar3(is_relative?mp_list_joff:mp_list_ioff,p1,arg1,arg2==~0U?_cimg_mp_boundary:arg2);\n            } else {\n              if (!imgin) _cimg_mp_return(0);\n              need_input_copy = true;\n              pos = scalar2(is_relative?mp_joff:mp_ioff,arg1,arg2==~0U?_cimg_mp_boundary:arg2);\n            }\n            memtype[pos] = -1; // Prevent from being used in further optimization\n            _cimg_mp_return(pos);\n          }\n\n          s0 = se1; while (s0>ss && (*s0!='[' || level[s0 - expr._data]!=clevel)) --s0;\n          if (s0>ss) { // Vector element\n            arg1 = compile(ss,s0,depth1,0,block_flags);\n            if (is_scalar(arg1)) {\n              variable_name.assign(ss,(unsigned int)(s0 - ss + 1)).back() = 0;\n              cimg::strellipsize(variable_name,64);\n              _cimg_mp_strerr;\n              throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                          \"CImg<%s>::%s: %s: Array brackets used on non-vector variable '%s', \"\n                                          \"in expression '%s'.\",\n                                          pixel_type(),_cimg_mp_calling_function,s_op,\n                                          variable_name._data,s0);\n            }\n            s1 = s0 + 1; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;\n\n            if (s1<se1) { // Two or three arguments -> sub-vector extraction\n              p1 = size(arg1);\n              arg2 = compile(++s0,s1,depth1,0,block_flags); // Starting index\n              s0 = ++s1; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;\n              arg3 = compile(s1,s0,depth1,0,block_flags); // Length\n              arg4 = s0<se1?compile(++s0,se1,depth1,0,block_flags):1; // Step\n              _cimg_mp_check_const_scalar(arg3,2,3);\n              arg3 = (unsigned int)mem[arg3];\n              pos = vector(arg3);\n              CImg<ulongT>::vector((ulongT)mp_vector_crop,pos,arg1,p1,arg2,arg3,arg4).move_to(code);\n              return_comp = true;","sourceCodeStart":19858,"sourceCodeEnd":19894,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L19858-L19894","documentation":"Square-bracket element access 'name[...]' is only valid on vector variables. When the compiler detects that the base name compiles to a scalar (is_scalar(arg1)), it rejects array-bracket usage with this error.","triggerScenarios":"Using 'x[2]' where x is a scalar variable or scalar constant rather than a vector, inside a math-parser expression.","commonSituations":"Confusing scalar variables with vectors, assuming all variables support element indexing, porting code where x used to be a vector.","solutions":["Define the base as a vector first (e.g. 'x = vector(4)')","Remove the bracket indexing if the value is scalar","Rename variables to avoid shadowing a vector with a scalar"],"exampleFix":"// before\nx = 3; y = x[0];\n// after\nx = vector(1,3); y = x[0];","handlingStrategy":"type-guard","validationCode":"// Track scalar vs vector variables in your expression\nfunction expectsVector(name, vectorVars) {\n  return vectorVars.has(name); // only index names known to be vectors\n}\n","typeGuard":"function isVectorVar(name, declared) {\n  return declared.get(name) === 'vector';\n}\n// use: if (!isVectorVar('x', decl)) throw new Error('x is scalar, cannot index');\n","tryCatchPattern":"try {\n  img.evaluate(expr);\n} catch (e) {\n  if (/Array brackets used on non-vector/.test(String(e))) {\n    // define the base as a vector or drop indexing\n  } else throw e;\n}\n","preventionTips":["Initialize vectors with vector(n) before bracket access","Do not reuse a vector's name for a scalar value","Comment variable kinds (scalar/vector) in generated expressions"],"tags":["cimg","math-parser","vector","indexing"],"backgroundTag":"type-mismatch","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}