{"record":{"id":"a182a8a703899a16","repo":"Yalantis/uCrop","slug":"cimglist-s-fft-failed-to-allocate-memory-s","errorCode":null,"errorMessage":"CImgList<%s>::FFT(): Failed to allocate memory (%s) for computing FFT of image (%u,%u,%u,%u) along the X-axis.","messagePattern":"CImgList<(.+?)>::FFT\\(\\): Failed to allocate memory \\((.+?)\\) for computing FFT of image \\(%u,%u,%u,%u\\) along the X-axis\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"critical","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":47680,"sourceCode":"                                    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      const char _axis = cimg::lowercase(axis);\n      if (_axis!='x' && _axis!='y' && _axis!='z')\n        throw CImgArgumentException(\"CImgList<%s>::FFT(): Invalid specified axis '%c' for real and imaginary parts \"\n                                    \"(%u,%u,%u,%u) \"\n                                    \"(should be { x | y | z }).\",\n                                    pixel_type(),axis,\n                                    real._width,real._height,real._depth,real._spectrum);\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) along the X-axis.\",\n                                    pixel_type(),\n                                    cimg::strbuffersize(sizeof(fftw_complex)*real._width*real._height*real._depth),\n                                    real._width,real._height,real._depth,real._spectrum);\n      double *const ptrf = (double*)data_in;\n      fftw_plan data_plan =\n        _axis=='x'?fftw_plan_many_dft(1,(int*)&real._width,real.height()*real.depth(),\n                                      data_in,0,1,real.width(),\n                                      data_in,0,1,real.width(),\n                                      is_inverse?FFTW_BACKWARD:FFTW_FORWARD,FFTW_ESTIMATE):\n        _axis=='y'?fftw_plan_many_dft(1,(int*)&real._height,real.width()*real.depth(),\n                                      data_in,0,1,real.height(),\n                                      data_in,0,1,real.height(),\n                                      is_inverse?FFTW_BACKWARD:FFTW_FORWARD,FFTW_ESTIMATE):\n        fftw_plan_many_dft(1,(int*)&real._depth,real.width()*real.height(),\n                           data_in,0,1,real.depth(),\n                           data_in,0,1,real.depth(),\n                           is_inverse?FFTW_BACKWARD:FFTW_FORWARD,FFTW_ESTIMATE);","sourceCodeStart":47662,"sourceCodeEnd":47698,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L47662-L47698","documentation":"When CImg is built with FFTW3 (cimg_use_fftw3), FFT() allocates a temporary fftw_complex buffer of size width*height*depth via fftw_malloc. If that allocation fails (returns NULL), this CImgInstanceException is thrown naming the requested buffer size and image dimensions. It signals the process could not obtain the memory needed for the X-axis transform.","triggerScenarios":"Calling CImgList<T>::FFT()/CImg<T>::FFT() on a 3D image whose width*height*depth*sizeof(fftw_complex) exceeds available memory, while compiled with cimg_use_fftw3, computing along the X-axis.","commonSituations":"Processing very large volumes (e.g. 2048^3 or bigger), 32-bit address-space exhaustion, memory fragmentation, or running inside a container with a low memory limit/cgroup cap.","solutions":["Reduce input image size (crop, downsample, or tile the volume) before FFT.","Increase available memory: raise container/cgroup limits, move to a 64-bit build, or free other allocations.","Process the FFT axis-by-axis on smaller sub-volumes instead of the whole image at once.","Check for memory leaks elsewhere that progressively exhaust the heap."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"size_t bytes = sizeof(fftw_complex) * (size_t)img.width()*img.height()*img.depth();\nif (bytes > availableMemoryBudget()) throw std::runtime_error(\"FFT buffer too large\");","typeGuard":null,"tryCatchPattern":"try { list.FFT(is_inverse); }\ncatch (CImgInstanceException& e) { std::cerr << \"FFT alloc failed, reducing size: \" << e.what(); /* fall back to smaller ROI */ }","preventionTips":["Estimate temporary buffer size (16 bytes per voxel) before FFT on 3D data","Run FFT-capable pipelines in 64-bit builds","Set container memory limits comfortably above the largest expected volume","Tile large volumes instead of transforming whole volumes at once"],"tags":["cimg","fft","memory","allocation"],"backgroundTag":"memory-allocation-failed","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"}