Results 1 to 3 of 3

Thread: access violation writing location

  1. #1
    Join Date
    May 2010
    Posts
    13

    Default 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:
    Qt Code:
    1. {
    2. // image has alpha format but is really opaque, so try to do a
    3. // more efficient conversion
    4. if (sourceImage.format() == QImage::Format_ARGB32
    5. || sourceImage.format() == QImage::Format_ARGB32_Premultiplied)
    6. {
    7. if (!inPlace)
    8. sourceImage.detach();
    9. sourceImage.d->format = QImage::Format_RGB32; //<<=========== Debugger is here.
    10. }
    11. format = opaqueFormat;
    12. } else {
    13. format = alphaFormat;
    14. }
    To copy to clipboard, switch view to plain text mode 


    The above function gets called due to the following code in my source file:
    Qt Code:
    1. QPixmap thisPic;
    2. if (thisPic.load(itr->second.c_str()) == false ){ //<<<==== this line causing the access violation
    3. std::cerr << "Could not load pixmap from " << itrZ->second.c_str() << std::endl;
    4. } else {
    5. ..... other code...
    6. }
    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.

  3. #3
    Join Date
    May 2010
    Posts
    13

    Default 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.

Similar Threads

  1. Access violation using QTableWidget
    By mchome in forum Newbie
    Replies: 2
    Last Post: 4th September 2012, 07:39
  2. Access violation -- qobject.cpp
    By willief in forum Newbie
    Replies: 9
    Last Post: 14th February 2011, 22:55
  3. Access Violation - Crashing Application
    By LIRiot in forum Qt Programming
    Replies: 9
    Last Post: 5th December 2010, 23:10
  4. Access Violation with VS2008
    By Takatschio in forum Qt Programming
    Replies: 3
    Last Post: 19th August 2010, 09:16
  5. OpenCV causes access violation only during timerEvent
    By derekkingston in forum Qt Programming
    Replies: 5
    Last Post: 19th February 2010, 08:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.