{"record":{"id":"51bb2c5f4906fd3a","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-undef","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: Undefined variable '%s' in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): Undefined variable '(.+?)' in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":24755,"sourceCode":"\n#ifdef cimg_mp_operator_dollar\n        if (*ss=='$' && ss1<se) // External variable '$varname'\n          _cimg_mp_const_scalar(cimg_mp_operator_dollar(variable_name._data + 1));\n#endif\n\n        // No known item found, assuming this is an already initialized variable.\n        if (cimg::is_varname(variable_name)) { // Valid variable name\n          get_variable_pos(variable_name,arg1,arg2);\n          arg1 = arg2!=~0U?reserved_label[arg2]:arg1!=~0U?variable_pos[arg1]:~0U;\n          if (arg1!=~0U) _cimg_mp_return(arg1);\n        }\n\n        // Reached an unknown item -> error.\n        c1 = *se1;\n        cimg::strellipsize(variable_name,64);\n        _cimg_mp_strerr;\n        if (is_sth)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: Undefined variable '%s' in expression '%s'.\",\n                                      pixel_type(),_cimg_mp_calling_function,\n                                      variable_name._data,s0);\n        s1 = std::strchr(ss,'(');\n        s_op = s1 && c1==')'?\"function call\":\"item\";\n        throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                    \"CImg<%s>::%s: Unrecognized %s '%s' in expression '%s'.\",\n                                    pixel_type(),_cimg_mp_calling_function,\n                                    s_op,variable_name._data,s0);\n      }\n\n      // Evaluation procedure.\n      double operator()(const double x, const double y, const double z, const double c) {\n        mem[_cimg_mp_slot_x] = x; mem[_cimg_mp_slot_y] = y; mem[_cimg_mp_slot_z] = z; mem[_cimg_mp_slot_c] = c;\n        for (p_code = code; p_code<p_code_end; ++p_code) {\n          opcode._data = p_code->_data;\n          const ulongT target = opcode[1];\n          mem[target] = _cimg_mp_defunc(*this);","sourceCodeStart":24737,"sourceCodeEnd":24773,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L24737-L24773","documentation":"The CImg math parser tokenizes the expression and resolves each identifier. When an item is neither a known variable, named constant, function, nor operator, the parser reaches the 'unknown item' fallback. If the token is followed by something indicating a value context (is_sth), it reports 'Undefined variable' naming the token after ellipsizing it to 64 chars.","triggerScenarios":"Evaluating an expression referencing an identifier never assigned (e.g. via named variables passed to fill()/math()), a misspelled built-in constant, or using a variable outside the scope where it was defined.","commonSituations":"Typo in variable names inside fill() formulas; forgetting to pass named values/images to the expression; expressions copied from examples that rely on different predefined variables; renaming variables without updating expressions.","solutions":["Check the identifier spelling against the variables you actually defined/passed.","Define the variable before evaluation (assign it in the expression or pass it as a named value).","Use only built-in symbols valid for your CImg version (check docs for the version in use).","Simplify the expression to isolate which token is unresolved.","Add a sanity test that evaluates the expression with known inputs before deploying."],"exampleFix":"// before\nimg.fill(myValue*2); // 'myValue' never defined\n// after\nimg.fill(42*2);       // or define/bind myValue before evaluation","handlingStrategy":"validation","validationCode":"Set<String> defined = Set.of(\"i\",\"x\",\"y\",\"z\",\"c\",\"pi\"); // plus user-bound names\nfor (String id : extractIdentifiers(expression))\n    if (!defined.contains(id)) throw new IllegalArgumentException(\"undefined variable: \" + id);","typeGuard":null,"tryCatchPattern":"try {\n    img.fill(expression);\n} catch (CImgInstantiationException e) {\n    if (e.getMessage().contains(\"Undefined variable\")) {\n        // log offending identifier from message, bind or correct it\n    }\n    throw e;\n}","preventionTips":["Maintain a whitelist of valid variables for your expressions.","Bind all needed values explicitly before evaluation.","Grep for renamed variables when refactoring expression-generating code.","Pin the CImg version so built-in symbol names are stable."],"tags":["cimg","math-parser","undefined-variable","expression"],"backgroundTag":"resource-not-found","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"}