GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.48k stars 282 forks source link

dilate() / erode() crashes on Windows for large images #342

Closed pentekq closed 2 years ago

pentekq commented 2 years ago

Hello,

The execution of the following code leads to a segmentation fault on windows (tested on 2 computers with Windows 10 and 11) but not Linux (Ubuntu 20.04):

cimg_library::CImg<unsigned char> img(50000,50000,1,1,255);
img.dilate(2);

The error appears in the dilate() function at line 37983 (cimg_version 291) The same goes for the erode() function or when I change the image type to float. If I reduce the image size to img(40000,40000,1,1,255) everything goes well. I had enough available RAM in all my tests. Is there any reason that could explain this behavior?

dtschump commented 2 years ago

Thanks for reporting. Does this happen also with the very latest version ? (3.1.0_pre033122).

pentekq commented 2 years ago

I'm not sure what you meant by 3.1.0_pre033122 version but I tested with the 3.1.0 (latest version on master and on develop) and yes I get the same error (line 39691)

dtschump commented 2 years ago

That is useful, thanks. At a first glance, I don't know what happens but I'll investigate. When on Windows, what compiler did you use ?

pentekq commented 2 years ago

MSVC 14.26 (Windows 11) and MSVC 14.29 (Windows 10)

dtschump commented 2 years ago

Thanks. I confirm that. I think I've found a fix : https://github.com/dtschump/CImg/commit/d0f152d53aff1d8cb002e05af7f13b93d6dce7e1 I've released a new version of the CImg package, with this fix included : https://cimg.eu/download (pre-release 040122) Could you please test it and tell me if that solves your issue ?

pentekq commented 2 years ago

Your fix indeed solves this issue! Thanks a lot for your incredible responsiveness and for this great software !!