access violation writing location c++
access violation writing location
Hi,I am getting "access violation writing location 0x00000020" on VS2010 (Windows 7) while I try to read a big tiff file into a QPixmap. The visual debugger bring me at the following location in qpixmap_raster.cpp where it says the problem is occurring:
{
// image has alpha format but is really opaque, so try to do a
// more efficient conversion
if (sourceImage.format ( ) == QImage :: Format_ARGB32
|| sourceImage.format ( ) == QImage :: Format_ARGB32_Premultiplied )
{
if ( !inPlace)
sourceImage.detach ( );
sourceImage.d ->format = QImage :: Format_RGB32; //<<=========== Debugger is here.
}
format = opaqueFormat;
} else {
format = alphaFormat;
}
{ // image has alpha format but is really opaque, so try to do a // more efficient conversion if (sourceImage.format() == QImage::Format_ARGB32 || sourceImage.format() == QImage::Format_ARGB32_Premultiplied) { if (!inPlace) sourceImage.detach(); sourceImage.d->format = QImage::Format_RGB32; //<<=========== Debugger is here. } format = opaqueFormat; } else { format = alphaFormat; }To copy to clipboard, switch view to plain text mode
The above function gets called due to the following code in my source file:
if (thisPic.load (itr->second.c_str ( ) ) == false ) { //<<<==== this line causing the access violation
std:: cerr << "Could not load pixmap from " << itrZ->second.c_str ( ) << std:: endl;
} else {
..... other code...
}
QPixmap thisPic; if (thisPic.load(itr->second.c_str()) == false ){ //<<<==== this line causing the access violation std::cerr << "Could not load pixmap from " << itrZ->second.c_str() << std::endl; } else { ..... other code... }To copy to clipboard, switch view to plain text mode
The above problem is using Qt 4.8.6 on a Windows 7 box, MS VS2010, compiled in Win32 mode.
However, it turns out that the program runs fine on a Linux box, in 64 bits, using Qt 4.8.7. Also runs fine on a Windows 7 box while compiled in 64 bit mode, running Qt 5.6.
Now, granted that I am reading in large images, around 40 MB, a total of 9 images. Could be stack related issues? How should I go about finding out the exact problem? Advice?
Thanks.
Re: access violation writing location
It could be either a stack or heap-related issue. In 32-bit Windows, your program can only request about 1 GB of heap, regardless of how much RAM you have. If your 40 MB TIFF files expand to a much larger size when in RGB32 format, or if you make multiple copies of them, you could easily be running out of memory. If you frequently load / unload images or do other operations which request memory, then you could be fragmenting your heap. Heap allocations must be contiguous, so if you have a fragmented heap and ask for more than is available in one chunk, the request will fail. Windows memory management is not very smart, from what I can tell. Two adjacent free areas of the heap will be merged into one larger area when possible, but if two areas have a small chunk in between that is still allocated, it stays fragmented.Windows is nice about handling failed memory allocations. It simply crashes your program to prevent you from asking for any more memory. You can use Task Manager to get a rough idea about how much memory your program is using. If it is typical of most program, the amount shown by TM will increase quickly as your program starts and you do some initial operations, but then should level off. If memory usage continues to grow, then it could be a sign that you are fragmenting the heap and the program is forced to request more and more from the OS.
Re: access violation writing location
Thanks for the info. Recompiling Qt and my application on x64 platform using Visual Studio 2010 solved the problem. It was just matter of needing more stack/heap space for all the image data.
access violation writing location c++
Source: https://qtcentre.org/threads/65715-access-violation-writing-location
Posted by: jonesbobjections.blogspot.com
0 Response to "access violation writing location c++"
Post a Comment