You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory Access violation when saving a png image #6198
Hi I'm using opencv 3 (x86) in windows 10 , I tried also to compile the 3.1 version but I have the same problem.
I'm getting an exception when saving a png image with 4 channels.
Here is the code (is the example in the docs):
The strange thing is that the exception is not always thrown (3 times out of 4) so I hacked the problem with a try catch inside a loop. But this should not be the final solution...
string destinationNamePath = "";
int count = 0;
while (count < 1000)
{
count++;
destinationNamePath = generateUniqueFileName(pngDestinationPath);
// If the file already exists then I may cannot overwrite it
if (!System.IO.File.Exists(destinationNamePath))
{
// Return false if an exception is thrown
if (ImageProcessingWrap.ImageProcessing.MakeTransparent(sourceNamePath, destinationNamePath)) break;
}
}
return destinationNamePath;
And this is the result:
The png generated with the exception are corrupted.
Activity
Dikay900 commentedon Mar 2, 2016
You do not use the compression_params variable.
Are you using the compression params or is the exception thrown with the actual code you provided?
mpp commentedon Mar 2, 2016
Sorry, my fault: somehow when copied the code I dropped that variable. I updated the code.
mshabunin commentedon Mar 2, 2016
Works for me in Ubuntu for both 3.1.0 and latest master with this example code.
Please try to make clean builds of OpenCV and your sample application. Try to check latest master branch version.
mpp commentedon Mar 2, 2016
It's what i did with opencv 3.1
The strange thing is that the exception is not always thrown (3 times out of 4) so I hacked the problem with a try catch inside a loop. But this should not be the final solution...
mpp commentedon Mar 3, 2016
This is the code:
And this is the result:

The png generated with the exception are corrupted.
Is there a better solution in your opinion?
Thanks
alalek commentedon Mar 3, 2016
Please add information about MSVS version and output of "
std::cout << cv::getBuildInformation().c_str() << std::endl;"mpp commentedon Mar 3, 2016
I have Visual Studio 2013
The output is:
alalek commentedon Mar 3, 2016
Thanks for update!
Do you use "Debug" or "Release" build?
mpp commentedon Mar 3, 2016
I use both and get the exception in both configurations!
Thanks for your help
alalek commentedon Mar 3, 2016
Unfortunately I can't reproduce problem with sample above.
I used MSVS 2013 Express (x86 / Debug) and wrote 1000 images:
So we can't debug this problem on our side.
You can try to add some "debug code" before and after
imwritecall and into the "catch" block (and intoPngEncoder::writefunction):PkLab commentedon Dec 16, 2016
might be this same as #5227 ?