[Interest] Advice on random program finish crash
Michael Sué
sue at sf.mpg.de
Wed Jan 7 13:31:26 CET 2015
Hi,
With this approach, the object will no longer be deleted at program exit, right? So there can be no crash on deletion anymore.
- Michael.
From: interest-bounces+sue=sf.mpg.de at qt-project.org [mailto:interest-bounces+sue=sf.mpg.de at qt-project.org] On Behalf Of Nuno Santos
Sent: Wednesday, January 07, 2015 1:16 PM
To: Igor Mironchik
Cc: Interests Qt
Subject: Re: [Interest] Advice on random program finish crash
Hi,
I have made the following modification and it seems not crashing anymore:
static Manager* gManager = 0;
Manager* Manager::sharedManager()
{
QMutexLocker lock(&managerMutex);
if (!gManager)
{
gManager = new Manager();
}
return gManager;
}
Does this seems a better approach?
Regards,
Nuno
On 07 Jan 2015, at 10:30, Nuno Santos <nunosantos at imaginando.pt> wrote:
Hi Igor,
Ops… You are right, it is not static.
I have tried your suggestion but now it crashes everytime I close the app and I can’t even get a stack trace like before. If I run it on debug, it points me to assembler code. Not anything I can really point to.
Regards,
Nuno
On 07 Jan 2015, at 10:19, Igor Mironchik <igor.mironchik at gmail.com> wrote:
On Wed, 07 Jan 2015 13:01:32 +0300, Nuno Santos < <mailto:nunosantos at imaginando.pt> nunosantos at imaginando.pt> wrote:
Yes,
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
...
return app.exec();
}
No. Here QGuiApplication is not static. Then in your app the situation is the next: QGuiApplication destroyes before your Manager. But any QObject-derived class must be created after QApplication and destroyed before QApplication. May be this is the reason of your crash.
Make QGuiApplication static. For example:
static QSharedPointer< QApplication > application( int argc = 0, char ** argv = 0 )
{
static QSharedPointer< QApplication > app(
new QApplication( argc, argv ) );
return app;
}
and in main()
QSharedPointer< QApplication > app = application( argc, argv );
before any QObject...
On 07 Jan 2015, at 09:54, Igor Mironchik <igor.mironchik at gmail.com> wrote:
Hi, I have one question: is QApplication static too?
On Wed, 07 Jan 2015 12:32:21 +0300, Nuno Santos <nunosantos at imaginando.pt>
wrote:
Hi,
I’m having a problem with a random crash that not always happens. I
would like to have your advice on how to find the origin of it.
This crash always happens on program exit and the stack trace is the
following:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 org.qt-project.QtCore 0x0000000109a03549
QMutexPrivate::allocate() + 105
1 org.qt-project.QtCore 0x0000000109a02d1c
QBasicMutex::lockInternal(int) + 92
2 org.qt-project.QtCore 0x0000000109a02c64 QMutex::lock() + 52
3 org.qt-project.QtCore 0x0000000109a0b6fd
QWaitCondition::wait(QMutex*, unsigned long) + 173
4 org.qt-project.QtCore 0x0000000109a0aeae
QThread::wait(unsigned long) + 110
5 org.qt-project.QtNetwork 0x000000010a4870da
QNetworkAccessManagerPrivate::~QNetworkAccessManagerPrivate() + 58
6 org.qt-project.QtNetwork 0x000000010a48722e
QNetworkAccessManagerPrivate::~QNetworkAccessManagerPrivate() + 14
7 org.qt-project.QtCore 0x0000000109c3e7c7
QObject::~QObject() + 1879
8 org.qt-project.QtNetwork 0x000000010a483c16
QNetworkAccessManager::~QNetworkAccessManager() + 262
The only particularity of this QNetworkAccessManager is the fact that it
is instantiated on a class that is a singleton:
class Manager : public QObject
{
public:
static Manager* sharedManager();
...
QNetworkAccessManager* networkAccessManager();
...
protected:
Manager();
~Manager();
...
QNetworkAccessManager _networkAccessManager;
};
Manager* Manager::sharedManager()
{
QMutexLocker lock(&managerMutex);
static Manager manager;
return &manager;
}
Manager::Manager() :
_networkAccessManager()
{
...
}
Manager::~Manager()
{
}
Is there any obvious reason for this crash to happen randomly at program
termination?
Thanks,
Regards,
Nuno Santos
_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
--
Best Regards,
Igor Mironchik.
_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
--
Best Regards,
Igor Mironchik.
_______________________________________________
Interest mailing list
<mailto:Interest at qt-project.org> Interest at qt-project.org
<http://lists.qt-project.org/mailman/listinfo/interest> http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150107/67ee0dac/attachment.html>
More information about the Interest
mailing list