Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Thread has crashed: A data abort exception has occurred accessing 0x2d
Qt 6.11 is out! See what's new in the release blog

Thread has crashed: A data abort exception has occurred accessing 0x2d

Scheduled Pinned Locked Moved Mobile and Embedded
16 Posts 4 Posters 10.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    microwish
    wrote on last edited by
    #1

    Did anyone encounter problems with fatal error: "Thread has crashed: A data abort exception has occurred accessing 0x2d".

    The space address, 0x2d in this case, could change to 0x24, 0x25, 0x27, 0x2e and the like.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Maybe a not initialized pointer?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        microwish
        wrote on last edited by
        #3

        no uninitialized pointers at all......

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          A simple code sample would be helpful then.

          Also, run the program in debug mode and use a debugger to see where the crash actually happens.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • M Offline
            M Offline
            microwish
            wrote on last edited by
            #5

            @/* header file */
            #ifndef _WEIBOIMAGEPROVIDER_H
            #define _WEIBOIMAGEPROVIDER_H

            #include <QDeclarativeImageProvider>
            #include <QImage>
            #include <QString>
            #include <QSize>
            #include <QUrl>
            #include <QObject>

            class QNetworkAccessManager;

            class WeiboImageProvider:
            public QObject, public QDeclarativeImageProvider {
            Q_OBJECT

            public:
            WeiboImageProvider(QNetworkAccessManager *);
            ~WeiboImageProvider();
            QImage requestImage(const QString&, QSize *, const QSize&);

            Q_SIGNALS:
            void imageRequested(const QUrl&, const QString&);
            void imageDone();

            public slots:
            void generateImage(const QUrl&, const QString&);

            private:
            QString locateImage(const QUrl&);

            private:
            QNetworkAccessManager *_accMgr;
            };

            #endif

            /* implementation file */
            #include "weiboimageprovider.h"

            #include <QNetworkAccessManager>
            #include <QNetworkReply>
            #include <QNetworkRequest>
            #include <QFile>
            #include <QDir>
            #include <QFileInfo>
            #include <QIODevice>
            #include <QEventLoop>
            #include <QDebug>

            WeiboImageProvider::WeiboImageProvider(QNetworkAccessManager *accessManager):
            QObject(0),
            QDeclarativeImageProvider(QDeclarativeImageProvider::Image)
            {
            _accMgr = accessManager;
            qDebug("_accMgr addr: %p", _accMgr);
            }

            WeiboImageProvider::~WeiboImageProvider()
            {
            }

            QImage WeiboImageProvider::requestImage(const QString& id,
            QSize *size, const QSize& requestedSize)
            {
            if(id.indexOf("http", 0, Qt::CaseInsensitive) != 0)
            return QImage();

            (void)size;
            (void)requestedSize;

            /*
            int width = 50, height = 50;

            if(size) {
            if(requestedSize.isEmpty())
            *size = QSize(width, height);
            else
            *size = QSize(requestedSize.width(), requestedSize.height());
            }
            */

            QUrl imageUrl = QUrl(id);
            QString imagePath = locateImage(imageUrl);

            if(QFile::exists(imagePath)) {
            if(QFile(imagePath).size() > 0)
            return QImage(imagePath);
            }

            //generateImage(imageUrl, imagePath);
            emit imageRequested(imageUrl, imagePath);

            //force to block
            QEventLoop eventLoop;
            QObject::connect(this, SIGNAL(imageDone()), &eventLoop, SLOT(quit()));
            eventLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);

            return QImage(imagePath);
            }

            void WeiboImageProvider::generateImage(const QUrl& imageUrl, const QString& imagePath)
            {
            qDebug() << "start generateImage";
            qDebug() << "image URL: " << imageUrl.toString();

            QNetworkReply *reply = _accMgr->get(QNetworkRequest(imageUrl));
            qDebug("reply addr: %p", reply);

            qDebug() << "blocking";
            //force to block
            QEventLoop eventLoop;
            QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
            eventLoop.exec(QEventLoop::ExcludeUserInputEvents);

            qDebug() << "write file: " << imagePath;
            QFile imageFile(imagePath);
            imageFile.open(QIODevice::WriteOnly);
            imageFile.write(reply->readAll());
            imageFile.flush();
            imageFile.close();
            qDebug() << "write OK: " << imagePath;

            reply->close();
            reply->~QNetworkReply();

            emit imageDone();

            qDebug() << "end generateImage";
            }

            QString WeiboImageProvider::locateImage(const QUrl& id)
            {
            //http://tp4.sinaimg.cn/1799583891/50/5616916109/1
            QString urlPath = id.path().mid(1);
            QString userId = urlPath.mid(0, urlPath.indexOf(QChar('/')));

            QDir imgDir("./qml/weiboimages");
            if(!imgDir.exists()) {
            qDebug() << "weibo image dir not exists";
            imgDir.mkpath("./qml/weiboimages");
            }

            return QFileInfo("./qml/weiboimages/" + userId).absoluteFilePath();
            }@

            1 Reply Last reply
            0
            • M Offline
              M Offline
              microwish
              wrote on last edited by
              #6

              @/* in main.cpp file */
              WeiboImageProvider *imgProvider = new WeiboImageProvider(viewer.engine()->networkAccessManager());

              QObject::connect(imgProvider, SIGNAL(imageRequested(const QUrl&, const QString&)), imgProvider, SLOT(generateImage(const QUrl&, const QString&)));

              viewer.engine()->addImageProvider("weiboimageprovider", imgProvider);@

              1 Reply Last reply
              0
              • F Offline
                F Offline
                favoritas37
                wrote on last edited by
                #7

                If you are developing for Symbian platform it could be because of a missing capability which is needed in order to use the networking modules. So if that is your case you should add the following in you .pro file:
                @
                symbian{
                TARGET.CAPABILITY += NetworkServices
                }
                @

                Also one other note, is the following code of yours legitimate? Do you really need to delete it?
                @
                reply->~QNetworkReply();
                @

                If it needs to be deleted then you better do the following:
                @
                delete reply;
                @

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  microwish
                  wrote on last edited by
                  #8

                  Yes, it's for the Symbian platform indeed. However, I've been always enabling the NetworkServices capability all the time in my .pro file.

                  The pointer variable "reply" is returned by QNetworkAccessManager::get(QNetworkRequest&), but not new-ed by manual, so I call the destructor explicitly instead of delete.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    You must not[1] call the destructor of a class directly. So the following line is forbidden:

                    @
                    reply->~QNetworkReply();
                    @

                    replace ist by

                    @
                    delete reply;
                    @

                    If your code still crashes, then please run in a debugger and tell us where.

                    Another recommendation:
                    If a class depends on certain signal slot connections within itself, then make the connections in that class, eg. the constructor or some init method, and do not make the connection somewhere outside:

                    @
                    // move this to the class
                    QObject::connect(imgProvider, SIGNAL(imageRequested(const QUrl&, const QString&)), imgProvider, SLOT(generateImage(const QUrl&, const QString&)));

                    // and change to
                    connect(this, SIGNAL(imageRequested(QUrl, QString)), this, SLOT(generateImage(QUrl, QString)));
                    @

                    fn1. There are rare situations (e.g. placement new) where it's ok to call the destructor. See the "C++ FAQs":http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.6 for details.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      microwish
                      wrote on last edited by
                      #10

                      Volker, thanks a lot.

                      I've run the GDB debugger integrated with Qt creator, but it told nothing related to the crash (such as where the segment fault happend) but the literal error information.

                      Moreover, would you kindly enough tell in detail why it is better to make the connection in the constructor?

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        Then I recommend running in the debugger and execute the code line by line. When it eventually crashes, you see where.

                        Because it's an internal implementation detail. Those should go into the class. And your class works without anyone outside needing to know that this connection has to be setup.

                        BTW:
                        You have two blocking event loops in your code. From how you use the code, I would say one is not necessary and it should be sufficient to call generateCode directly, not via a signal/slot.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          microwish
                          wrote on last edited by
                          #12

                          Just as you said, at the very beginning, I called generateImage (you mentioned as generateCode) directly instead of making use of signal/slot. However, if I did so, I always get the following error:

                          QObject: Cannot create children for a parent that is in a different thread.
                          (Parent is QNetworkAccessManager(0x*****), parent's thread is QThread(0x******), current thread is ResultThread(0x******)

                          And then, I use signal/slot to avoid that error.

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on last edited by
                            #13

                            You did read this "wiki article":wiki/Threads_Events_QObjects already, didn't you?

                            There's nothing to comment on the actual problem, your complete threading code is missing.

                            And as a first advice:
                            Think very hard if you really need threads in the first place. QNAM is asynchronous already.

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              microwish
                              wrote on last edited by
                              #14

                              I'm sorry that I failed opening the wiki article.

                              In fact, I didn't use threads directly in my codes. It should be some Qt classes I used that use threads.

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                Reptile
                                wrote on last edited by
                                #15

                                total shot in the dark, but try creating a new project with just the symbian target (skip simulator) and copy all your files over. that's how I got rid of the error when I had it...

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  goetz
                                  wrote on last edited by
                                  #16

                                  I don't understand how/where the "ResultThread" class comes into the game then - do you use any other classes or libraries that introduce threading in your application?

                                  http://www.catb.org/~esr/faqs/smart-questions.html

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved