Unhandled exception (msvcr120.dll) using imwrite()

asked 2020-06-17 20:03:26 -0500

M1978 gravatar image

updated 2020-07-16 19:47:04 -0500

I'm developing a software that has a few threads writing 10 to 50 bitmap files per second and sometimes I'm getting this exception.Each thread writes its bitmap files into different folders.

I tried cloning the cv::Mat just before imwrite(), or getting a lock before calling imwrite() but those didn't help.

Each threads uses this code to write bitmap files.

cv::Mat source_image;  // UINT8, 1x128x130

// do some processing to the source_image;

cv::Mat cloned_image = source_image.clone();
if ((cloned_image.rows > 0) && (cloned_image.cols  >0)) {
    cv::String file_name = "";  // somewhere
    cv::imwrite(file_name, cloned_image);  // THIS IS WHERE I GET THE EXCEPTION

I also checked the mini dump file (*.dmp) and the exception code was 0xC0000409.

Here is the stack info from the mini dump file.

msvcr120.dll!_invoke_watson(const wchar_t * pszExpression, const wchar_t * pszFunction, const wchar_t * pszFile, unsigned int nLine, unsigned __int64 pReserved) Line 132   C++
msvcr120.dll!_invalid_parameter(const wchar_t * pszExpression, const wchar_t * pszFunction, const wchar_t * pszFile, unsigned int nLine, unsigned __int64 pReserved) Line 85    C++
msvcr120.dll!_invalid_parameter_noinfo() Line 97    C++
msvcr120.dll!_write(int fh, const void * buf, unsigned int cnt) Line 66 C
msvcr120.dll!_fwrite_nolock(const void * buffer, unsigned __int64 size, unsigned __int64 num, _iobuf * stream) Line 166 C
msvcr120.dll!fwrite(const void * buffer, unsigned __int64 size, unsigned __int64 count, _iobuf * stream) Line 83    C
opencv_world300.dll!00007ffc0e265373()  unknown
opencv_world300.dll!00007ffc0e264745()  unknown
opencv_world300.dll!00007ffc0e256899()  unknown
opencv_world300.dll!00007ffc0e2532bb()  unknown
opencv_world300.dll!00007ffc0e252f36()  unknown
cv::imwrite(file_name, cloned_image);

Thank you.

edit retag flag offensive close merge delete


do you share any variable accross your program's threads?

urres_coding gravatar imageurres_coding ( 2020-06-18 01:51:36 -0500 )edit

Hi, urres_coding! No shared variables across the threads.

M1978 gravatar imageM1978 ( 2020-06-18 09:31:20 -0500 )edit

Googling shows that the code might imply stack overflow, but also pethaps running out of consecutive memory. So the problem might not be in threads as such or a local issue, but in general memory managent of how you handle the large number of images. And in C or C++ the problem might be anywhere...

mvuori gravatar imagemvuori ( 2020-06-19 11:06:48 -0500 )edit

whether is the source image is empty before write?

StefanCheung gravatar imageStefanCheung ( 2020-06-19 23:00:02 -0500 )edit

Hi, mvuori! I also googled and got results about stack overflow, but as my machine has a large free space of memory I excluded that possibility...

M1978 gravatar imageM1978 ( 2020-06-21 21:17:34 -0500 )edit

Hi, StefanCheung! I'm cloning the source image and checking the cloned image's size before calling cv::imwrite, so I don't think that the image is empty.

M1978 gravatar imageM1978 ( 2020-06-21 21:19:25 -0500 )edit


oh my, do you know, how old that is ?

berak gravatar imageberak ( 2020-07-17 04:21:42 -0500 )edit

Hi, berak! Well, I do know that is old, but I cannot update the library unless it's going to solve the very problem I'm dealing with...

M1978 gravatar imageM1978 ( 2020-09-02 23:35:20 -0500 )edit