Important: Please read the Qt Code of Conduct -

App crash on QImage::transformed (Qt 5.10)

  • Hello. I have app that gets images from photo cameras for future processing. Initialy I get images as QByteArray buffer and then process them as follows:

    QImage image;
    QMatrix rm;
    rm.rotate(90);//I need vertical aligned picture
    image.loadFromData(buf_);//buf_ is raw data QByteArray
        emit error();
    QImage trans_image = image.transformed(rm);, "JPG", 100);

    Regulary I get crash on QImage trans_image = image.transformed(rm), sometimes it takes 5-6 images, sometimes 50-60.

    Call stack looks like that:

    1   qt_memrotate270_tiled_unpacked<unsigned int>                                                                                      qmemrotate.cpp           212  0x1b2ec6c  
    2   qt_memrotate270_template<unsigned int>                                                                                            qmemrotate.cpp           275  0x1b2ec6c  
    3   qt_memrotate270                                                                                                                   qmemrotate.cpp           315  0x1b2ec6c  
    4   qt_memrotate270_32                                                                                                                qmemrotate.cpp           377  0x1b2ecd3  
    5   rotated90                                                                                                                         qimage.cpp               4520 0x1a07c3f  
    6   QImage::transformed                                                                                                               qimage.cpp               4627 0x1a0a502  
    7   QImage::transformed                                                                                                               qimage.cpp               2792 0x1a0b1ce  
    8   Camera::processImage                                                                                                              camera.cpp               293  0x438bea   

    Image variable looks pretty ok in debugger, not Invalid or anything like that, start of the buffer looks like proper jpeg header.
    Image size is 4000*6000px.
    It doesn't seem to be some memory leak problem, once it crashed when program only allocated around 100mb of RAM.
    Also this processing works in thread, maybe it is important.

    What can be reason for such crash and how can I deal with it (at least catch an error and tell user of it to avoid segfault)?

  • Moderators

    @Crazy-Sage said in App crash on QImage::transformed (Qt 5.10):

    What can be reason for such crash and how can I deal with it (at least catch an error and tell user of it to avoid segfault)?

    hard to say. In C/C++ it's easy that an arbitrary (on first sight unrelated) part of your code can cause be influencing and cause a crash, since it is possible to modify the memory from anywhere in your application.

    You can try to isolate the code and try to reproduce. I bet it wont crash, since the code part you've posted looks good.

    But also threading is a highly possible cause. You need to make sure that you protect resources that are shared among threads. (e.g. with a mutex).
    Or at least you need to make sure that each thread operates on a separate copy of data. So that no other thread interferes and is reading/writing the same data at the same time.

Log in to reply