{"record":{"id":"e038408ed4225f06","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-t","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: %s: Type of first arguments ('%s') does not match with third argument 'nb_channelsX=%u', in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Type of first arguments \\('(.+?)'\\) does not match with third argument 'nb_channelsX=%u', in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":22520,"sourceCode":"              _cimg_mp_check_const_scalar(arg3,3,3);\n              _cimg_mp_check_const_scalar(arg4,4,3);\n              _cimg_mp_check_type(arg5,5,1,0);\n              p1 = size(arg1);\n              p2 = size(arg2);\n              arg3 = (unsigned int)mem[arg3];\n              arg4 = (unsigned int)mem[arg4];\n              if (p1%arg3) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Type of first arguments ('%s') \"\n                                            \"does not match with third argument 'nb_channelsX=%u', \"\n                                            \"in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,\n                                            s_type(arg1)._data,arg3,s0);\n              }\n              if (p2%arg4) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Type of second arguments ('%s') \"\n                                            \"does not match with fourth argument 'nb_channelsP=%u', \"\n                                            \"in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,\n                                            s_type(arg2)._data,arg4,s0);\n              }\n              pos = vector(p1*arg4);\n              CImg<ulongT>::vector((ulongT)mp_map,pos,arg1,arg2,p1,p2,arg3,arg4,arg5).move_to(code);\n              return_comp = true;\n              _cimg_mp_return(pos);\n            }\n\n            if (!std::strncmp(ss,\"mul(\",4)) { // Matrix multiplication\n              _cimg_mp_op(\"Function 'mul()'\");\n              s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;\n              arg1 = compile(ss4,s1,depth1,0,block_flags);\n              s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;\n              arg2 = compile(s1,s2,depth1,0,block_flags);","sourceCodeStart":22502,"sourceCodeEnd":22538,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L22502-L22538","documentation":"The second divisibility check in the same multi-channel operator: after validating the first argument against nb_channelsX, CImg checks that the second argument's size p2 is divisible by nb_channelsP (arg4). If not, it throws this error naming the second argument's type and the P channel count. Note the message text in the corpus header is mislabeled ('first arguments'/'nb_channelsX') while the actual throw site reports the second argument and 'nb_channelsP'.","triggerScenarios":"Calling the same multi-channel function with a second (P, e.g. palette/secondary) vector whose length is not a multiple of nb_channelsP, e.g. second vector of 7 values with nb_channelsP=3.","commonSituations":"Mismatched channel layouts between the two inputs (one RGB, one RGBA); stale constants after changing one input's channel count; concatenating buffers of different channel widths.","solutions":["Ensure the second vector's length is an exact multiple of nb_channelsP","Set nb_channelsP to match the actual layout of the second argument (1/3/4)","Re-pad or re-generate the second buffer so its size aligns with the channel count","Check both divisibility conditions in code before invoking the expression to get clearer diagnostics"],"exampleFix":"// before\nimg.fill(\"op(dataX, [p0..p6], 3, 3)\"); // 7 not divisible by 3\n// after\nimg.fill(\"op(dataX, [p0..p8], 3, 3)\"); // 9 divisible by 3","handlingStrategy":"validation","validationCode":"void checkChannelsP(double[] p, int nbChannelsP) {\n  if (p.length % nbChannelsP != 0)\n    throw new IllegalArgumentException(\"Input P size \" + p.length + \" not a multiple of nb_channelsP=\" + nbChannelsP);\n}","typeGuard":null,"tryCatchPattern":"try { img.fill(expr); } catch (CImgArgumentException e) { if (e.getMessage().contains(\"nb_channelsP\")) { /* fix secondary vector layout and retry */ } throw e; }","preventionTips":["Check both inputs' divisibility (X and P) before invoking the expression","Use one shared channel-layout constant for all vectors in the operation","Re-pad secondary buffers when channel counts change upstream"],"tags":["cimg","math-parser","channels","shape-mismatch"],"backgroundTag":"shape-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"}