Results 1 to 9 of 9

Thread: Getting a SIGSEGV error when loading a pixmap

  1. #1
    Join Date
    Nov 2016
    Location
    Ridgecrest California
    Posts
    33
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Getting a SIGSEGV error when loading a pixmap

    I'm using Qt 5.8.0 MinGW 32 bit from Qt Creator 4.2.1 on an HP desktop with a Intel Xeon CPU in Windows & Professional 64 bit service pack1 OS.
    I keep getting a segmentation fault when running this code (in debug) at the point where I attempt to load an image using QPixmap.

    I believe my pointers are initialized correctly nor can I notice any uninitialized pointers or out of bound arrays (unless I'm looking right at it and can't see it). In the following code, some of the documented out lines are various ways I've attempted to load the image.

    Header file...
    Qt Code:
    1. #ifndef OVERVIEW_H
    2. #define OVERVIEW_H
    3.  
    4. #include <QDialog>
    5. #include <QWidget>
    6. #include <QGeoRectangle>
    7. #include <QGraphicsScene>
    8. #include <QGraphicsObject>
    9.  
    10. #include "aircraft.h"
    11.  
    12. namespace Ui {
    13. class OverView;
    14. }
    15.  
    16. class OverView : public QDialog
    17. {
    18. Q_OBJECT
    19.  
    20. public:
    21. explicit OverView(QWidget* pParent = 0);
    22. ~OverView();
    23.  
    24. private slots:
    25. void showRange(int range); // Setup background
    26. void on_closeBtn_clicked();
    27.  
    28. private:
    29. Ui::OverView* ui;
    30.  
    31. void setUpWindow();
    32.  
    33. QString sMessage;
    34. QString sRangeFileNm; // Holds selected range file name
    35.  
    36. // QPixmap static rangePic; // The selected range image
    37. QGraphicsScene* pRangeScene; // Graphic scene pointer
    38.  
    39. //____________________________________________________________
    40. // Range background images from the resource file data.qrc
    41. QString sBothFileNm = ":/Data/Images/BothRanges2000.gif";
    42. QString sNorthFileNm = ":/Data/Images/NorthRange2000_2000.gif";
    43. QString sSouthFileNm = ":/Data/Images/SouthRange2000_2000.gif";
    44. };
    45.  
    46. #endif // OVERVIEW_H
    To copy to clipboard, switch view to plain text mode 

    cpp file...
    Qt Code:
    1. #include "overview.h"
    2. #include "ui_overview.h"
    3. #include "ui_rddswindow.h"
    4.  
    5. OverView::OverView(QWidget* pParent) :
    6. QDialog(pParent),
    7. ui(new Ui::OverView)
    8. {
    9. ui->setupUi(this);
    10.  
    11. setUpWindow();
    12. showRange(0); // Set the default background
    13. }
    14.  
    15.  
    16. /*---- setUpWindow -------------------------------------------------------------------
    17. Sets up the elements of the range view window. The combination box
    18. allows user to select the range to use as background and connects the
    19. combination box signal to the showRange slot.
    20. */
    21. void OverView::setUpWindow()
    22. {
    23. setWindowTitle("Range View");
    24. this->setObjectName("RangeView");
    25.  
    26. QStringList selectedRange;
    27. selectedRange << "Both Ranges" << "North Range"<< "Echo Range";
    28.  
    29. ui->rangeCmbBox->addItems(selectedRange);
    30. QObject::connect(ui->rangeCmbBox, SIGNAL(currentIndexChanged(int)),
    31. this, SLOT(showRange(int)));
    32.  
    33. ui->rangeView->setDragMode(QGraphicsView::ScrollHandDrag);
    34. }
    35.  
    36. /*---- showRange --------------------------------------------------------------------------
    37. Sets the background image and scaling based on an index value provided
    38. by the rangeCmbBox in the range view.
    39. 0 - Both north and south ranges
    40. 1 - North range
    41. 2 - South range
    42. */
    43. void OverView::showRange(int range)
    44. {
    45. QBrush rangeBackground;
    46. sRangeFileNm.clear();
    47.  
    48. switch(range){
    49. case 0: // Default image is both ranges
    50. sRangeFileNm.append(sBothFileNm);
    51. break;
    52. case 1:
    53. sRangeFileNm.append(sNorthFileNm); // North range image
    54. break;
    55. default:
    56. sRangeFileNm.append(sSouthFileNm); // South range image
    57. break;
    58. }
    59. // QPixmap const rangePic(sRangeFileNm);
    60. QPixmap const rangePic = QPixmap(sRangeFileNm);
    61.  
    62. rangeBackground.setTexture(rangePic);
    63. ui->rangeView->setBackgroundBrush(rangeBackground);
    64. QRectF rangeRect = QRectF(QPointF(0,0), rangePic.size());
    65. ui->rangeView->setSceneRect(rangeRect);
    66. ui->rangeView->show();
    67. /*
    68. if(rangePic.load(sRangeFileNm)){ // Load the range picture
    69. rangeBackground.setTexture(rangePic);
    70. ui->rangeView->setBackgroundBrush(rangeBackground);
    71. QRectF rangeRect = QRectF(QPointF(0,0), rangePic.size());
    72. ui->rangeView->setSceneRect(rangeRect);
    73. ui->rangeView->show();
    74. sMessage.append("Successfully loaded range image");
    75. }else
    76. sMessage.append("Failed to load range image");
    77. */
    78. qDebug() << sMessage;
    79. }
    To copy to clipboard, switch view to plain text mode 

    I'd appreciate anyone who can spot why I'm getting a SIGSEV error on this and thank you in advance.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Getting a SIGSEGV error when loading a pixmap

    Instead of using the QPixmap constructor with the filename, try using QPixmap::load() and checking the return status to see whether you have actually loaded the pixmap successfully? It also isn't clear why you are assigning the pixmap to another pixmap, only to have both of them go out of scope when the method exits.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Getting a SIGSEGV error when loading a pixmap

    you can also run the application in a debugger and see on which line it segfaults.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. The following user says thank you to high_flyer for this useful post:

    Corny (18th May 2017)

  5. #4
    Join Date
    Nov 2016
    Location
    Ridgecrest California
    Posts
    33
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Getting a SIGSEGV error when loading a pixmap

    Yeah, assigning a pixmap to another pixmap is the result of having tried a bunch of different things and that just kinda hung on for a bit. I believe I have tried your suggestion (note the commented out sections). Seeing as how I had read that a static pixmap might help, I have also tried making the pixmap static within the function that I'm trying to load it in using the following lines of code...
    Qt Code:
    1. QPixmap static rangePic;
    2. if(!rangePic.load(sRangeFileNm))
    3. qDebug() << "Failed to load the image";
    To copy to clipboard, switch view to plain text mode 

    In any event, I am running it in a debugger, and it blows up at whatever line that has the load statement in it. The code never has the opportunity to reach the qDebug() statement. The "locals and expressions" window in the debugger, shows that rangePic (the name of the pixmap), has a size of 2000 x 2000 which is the size of the image I'm trying to load. So I am assuming that the image is at least getting loaded, and that the problem occurs at some point between the load and the qDebug() statement. That would indicate that the error doesn't occur at one of my lines of code, so you can see why I'm tempted to say that it's not a problem with what I've written. However, my experience with SIGSEGV errors is that the problem could be in the code at an earlier point than where the error is indicated. I'm still unsure what is causing it though.
    Last edited by Corny; 18th May 2017 at 18:29. Reason: updated contents

  6. #5
    Join Date
    Nov 2016
    Location
    Ridgecrest California
    Posts
    33
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Getting a SIGSEGV error when loading a pixmap

    As an addendum to my previous post, I previously had discovered in the Qt documentation, that all pixmaps are placed in a QpixmapCache and the default size for the QpixmapCache is 10240 KB. I wanted to load 2 images with a combined file size of 1846 KB which falls well within the default QPixmapCache size limit. Therefore, one would think that was not the problem. However I have made a smaller version (lower resolution) of the largest file (the one used in the above code) and have found that I no longer receive the SIGSEGV error, and it works as expected. It's not clear to me at this point if the QPixmapCache size limit is the issue or not. Qt provides a way to increase the limit, yet I have yet to find a discussion on the cost of doing so. Unfortunately, I have a requirement for the higher resolution image. In any event, if anyone knows of a discussion or any kind of information that covers this topic, I'd be happy to check it out.
    Thanks again to any who may reply.

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Getting a SIGSEGV error when loading a pixmap

    If I do the math, a 2000 x 2000 pixel image is 4 million pixels. If each pixel is a 32-bit RGBA value, this is 16 MB per image, more than the size of the cache for just one image. They are obviously compressed to a smaller size on disk.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #7
    Join Date
    Nov 2016
    Location
    Ridgecrest California
    Posts
    33
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Getting a SIGSEGV error when loading a pixmap

    I thought you might be correct d_stranz, so I dissected the image and determined that it only has a depth of 8.

    So, in the Qt 5.9 documentation under the Qt 5.8 - Qt GUI - C++ Classes – QpixmapCache description, it states in the ‘Detailed Description’ section, that “The initial cache limit is 10240 KB (10 MB); you can change this by calling setCacheLimit() with the required value. A pixmap takes roughly (width * height * depth)/8 bytes of memory.”

    If an image is 2000 pixels by 2000 pixels and the depth is 8 pixels, I get 4,000,000 divided by a depth of 8 bits per pixel = 500,000. Divide that by 8 bytes of memory (or should I divide by 64 bits of memory) I get 62,500. Therefore, two images would require a cache size of 125,000 bits, bytes or kilobytes?????

    Based on the above documentation, I am assuming that (width (in pixels) * height (in pixels) * depth (bits per pixel)) / bytes of memory returns a value that is in bytes. However it could just as easily be bits, bytes or KB. If someone could provide clarification on this, it would be highly appreciated.

  9. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Getting a SIGSEGV error when loading a pixmap

    Try the math again: (width * height * depth) / 8 = (2000 * 2000 * 8)/8 = 4 million bytes. "depth" is always in bits / pixel (not pixels), and the final division by 8 converts bits to 8-bit bytes.

    After you load the image, what does QPixmap::depth() say?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. The following user says thank you to d_stranz for this useful post:

    Corny (23rd May 2017)

  11. #9
    Join Date
    Nov 2016
    Location
    Ridgecrest California
    Posts
    33
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Getting a SIGSEGV error when loading a pixmap

    Yeah you're right, thanks. I divided instead of multiplying.

    As to the depth of the pixmap, it fails when loading so I can never get to the point to use the QPixmap::depth() function. The only data that the Locals and Expressions window displays for the image information is the following; width: 2000, height: 2000, nbytes: 16000000, format: 456327200, data: 0x6bcce780. Would I be wrong to assume that nbytes is the number of bytes? In any event, not sure that any of these values represent the depth.

    But, thanks to your assistance, I've eliminated the SIGSEGV issue (at least for now) and now receive "can't find linker symbol for virtual table for `QPixmap' value" in the application output. I'm going to do some searching to see I if can figure this new one out. I'm sure I'll post again if I can't. So d_stranz, thank you very much for your support to date.

Similar Threads

  1. Replies: 2
    Last Post: 11th October 2013, 12:16
  2. SIGSEGV Error when debugging with Qt creator.
    By jiapei100 in forum Qt Programming
    Replies: 5
    Last Post: 22nd July 2012, 13:19
  3. SIGSEGV Error: Very Strange
    By grayfox in forum Qt Programming
    Replies: 18
    Last Post: 16th January 2012, 15:50
  4. Qt OpenCV SIGSEGV error help
    By bobo in forum Newbie
    Replies: 3
    Last Post: 13th June 2011, 21:03
  5. Pixmap height / width without loading it
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 08:10

Tags for this Thread

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.