{"record":{"id":"4049caf62f77180f","repo":"Yalantis/uCrop","slug":"cimglist-s-fft-empty-specified-real-part","errorCode":null,"errorMessage":"CImgList<%s>::FFT(): Empty specified real part.","messagePattern":"CImgList<(.+?)>::FFT\\(\\): Empty specified real part\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":47930,"sourceCode":"        }\n        if (is_inverse) { real/=N; imag/=N; }\n      } break;\n      }\n#endif\n    }\n\n    //! Compute n-D Fast Fourier Transform.\n    /**\n       \\param[in,out] real Real part of the pixel values.\n       \\param[in,out] imag Imaginary part of the pixel values.\n       \\param is_inverse Tells if the forward (\\c false) or inverse (\\c true) FFT is computed.\n       \\param nb_threads Number of parallel threads used for the computation.\n         Use \\c 0 to set this to the number of available cpus.\n    **/\n    static void FFT(CImg<T>& real, CImg<T>& imag, const bool is_inverse=false,\n                    const unsigned int nb_threads=0) {\n      if (!real)\n        throw CImgInstanceException(\"CImgList<%s>::FFT(): Empty specified real part.\",\n                                    pixel_type());\n      if (!imag) imag.assign(real._width,real._height,real._depth,real._spectrum,(T)0);\n      if (!real.is_sameXYZC(imag))\n        throw CImgInstanceException(\"CImgList<%s>::FFT(): Specified real part (%u,%u,%u,%u,%p) and \"\n                                    \"imaginary part (%u,%u,%u,%u,%p) have different dimensions.\",\n                                    pixel_type(),\n                                    real._width,real._height,real._depth,real._spectrum,real._data,\n                                    imag._width,imag._height,imag._depth,imag._spectrum,imag._data);\n      cimg::unused(nb_threads);\n#ifdef cimg_use_fftw3\n      cimg::mutex(12);\n#ifndef cimg_use_fftw3_singlethread\n      fftw_plan_with_nthreads(nb_threads?nb_threads:cimg::nb_cpus());\n#endif\n      fftw_complex *data_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*real._width*real._height*real._depth);\n      if (!data_in)\n        throw CImgInstanceException(\"CImgList<%s>::FFT(): Failed to allocate memory (%s) \"\n                                    \"for computing FFT of image (%u,%u,%u,%u).\",","sourceCodeStart":47912,"sourceCodeEnd":47948,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L47912-L47948","documentation":"The static CImg<T>::FFT(real, imag, ...) entry point first checks that the real-part image is non-empty (operator! fails on empty instances, i.e. any zero dimension or null data). An empty real part has nothing to transform, so CImg throws this CImgInstanceException before doing any work. The imaginary part may be empty (it is then zero-filled), but the real part may not.","triggerScenarios":"Passing a default-constructed CImg<T>() or an assign()-cleared image as the real argument to the static FFT(real, imag, is_inverse, nb_threads); also passing an image whose data failed to load (e.g. load() on a missing file returned an empty image).","commonSituations":"Image loading failed silently earlier in the pipeline (empty result of CImg::load), wrong variable passed, or reusing an image after assign() without re-allocating it.","solutions":["Ensure the real image is properly constructed/loaded before calling FFT (check real.data() or if (real)).","Check the return of load()/IO calls: an empty image usually means the load failed; fix the file path or format first.","If the imaginary part is what you have, swap the arguments: FFT(imag, real) is not valid, but you can FFT a real image with an empty imag and it will be zero-filled.","Guard with if (!real) throw/log before calling FFT."],"exampleFix":"// before\nCImg<float> real; // default-constructed, empty\nCImg<float>::FFT(real, imag);\n// after\nCImg<float> real(\"input.png\");\nif (real) CImg<float>::FFT(real, imag);","handlingStrategy":"validation","validationCode":"if (!real || !real.data()) throw std::invalid_argument(\"FFT real part must be non-empty\");","typeGuard":"bool isNonEmpty(const CImg<T>& img) { return (bool)img && img.data() != nullptr; }","tryCatchPattern":"try { CImg<float>::FFT(real, imag); }\ncatch (CImgInstanceException& e) { std::cerr << \"Empty real part: check that the image loaded correctly\"; }","preventionTips":["Always check load() results for empty images before further processing","Never pass default-constructed CImg objects as the real FFT argument","Validate image non-emptiness at pipeline boundaries"],"tags":["cimg","fft","empty-image"],"backgroundTag":"empty-required-field","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"}