miro
miro

Reputation: 809

C++/Qt: crash on QCoreApplicationPrivate::sendPostedEvents

I'm having difficulties to fix following issue/crash. The program just keeps going around 30 minutes and then it crashes. Basically what the program does is (simplified):

runCalculations(const InputValues &dataIn, OutputValues &dataOut);
appendNewOutputValues(const OutputValues &dataOut){
   doSomeVerifications(dataOut);
   emit dataChanged(dataOut);
}
//In another class I'm listening to the signal and adding each dataOut to a QMap<QDateTime, QVariant>
onDataChanged(const OutputValues &dataOut){
   addToMap(dateTime, dataOut);
   emit mapChanged();
}

//After that I'm emitting a signal that the buffer was changed: This signal is connected to an QObject which takes new value and does some functionality with it.
onMapChanged(){
   map.getNewData(&newData);
   doSomethingWithNewData(newData);
}

I hope that the main idea should be clear from above example.

Approximately I'm sending 2400 signals/sec. All the data I'm using should take around 14MB, so that should be OK.

First I thought that the problem is that my event queue gets full, so I have added code below after each runCalculations():

QCoreApplication::instance()->sendPostedEvents();
QCoreApplication::instance()->processEvents();
QCoreApplication::instance()->sendPostedEvents(0, QEvent::DeferredDelete);

I have tried also only with processEvents, sendPostedEvents,... but the same result. When I run my program only with runCalculations method (without updating and sending signals) everything works fine. Problem is that from the debug info I'm not very much smarter.

I'm running on XP in Parallels, where I have dedicated 3GB of Ram and 2 cores.

qt_internal_proc QCoreApplication

Backtrace:

Thread 1 (Thread 3484.0x3ec):
#0  0x08b05fe0 in abort () from C:\Qt\4.8.4\bin\QtCored4.dll
No symbol table info available.
#1  0x08b6013d in __gnu_cxx::__verbose_terminate_handler () at ../../../../gcc-4.4.0/libstdc++-v3/libsupc++/vterminate.cc:93
    terminating = true
    t = <optimized out>
#2  0x08b0db8d in __cxxabiv1::__terminate (handler=0x8b60018 <__gnu_cxx::__verbose_terminate_handler()>) at ../../../../gcc-4.4.0/libstdc++-v3/libsupc++/eh_terminate.cc:38
No locals.
#3  0x08b73efb in std::terminate () at ../../../../gcc-4.4.0/libstdc++-v3/libsupc++/eh_terminate.cc:48
No locals.
#4  0x08b76956 in __cxxabiv1::__cxa_rethrow () at ../../../../gcc-4.4.0/libstdc++-v3/libsupc++/eh_throw.cc:116
    globals = 0x188f5f4c
    header = 0x762a7b90
#5  0x08aa69c3 in QCoreApplicationPrivate::sendPostedEvents (receiver=0x0, event_type=0, data=0x178e6ad0) at kernel/qcoreapplication.cpp:1582
    pe = @0x4e717fe0: {receiver = 0x178e6ce8, event = 0x0, priority = 0}
    e = 0x1adc1018
    r = 0x178e6ce8
    locker = {val = 395209469}
    startOffset = 0
    i = @0x178e6af4: 1
#6  0x08acb347 in qt_internal_proc (hwnd=0x5203ca <FMDataVerificator::createSockets()+3930>, message=1025, wp=0, lp=0) at kernel/qeventdispatcher_win.cpp:496
    localSerialNumber = 540804d
    msg = {hwnd = 0x5203ca <FMDataVerificator::createSockets()+3930>, message = 1025, wParam = 0, lParam = 0, time = 2285040, pt = {x = 2285016, y = 145536386}}
    app = 0x22fe70
    q = 0x178e6ce8
    result = 0
    d = 0x178e6d08
#7  0x7e418734 in USER32!GetDC () from C:\WINDOWS\system32\user32.dll
No symbol table info available.

Upvotes: 2

Views: 2125

Answers (1)

phyatt
phyatt

Reputation: 19102

As far as I know I don't think you can exceed the capacity of the Event Queue. I would look other places before pointing at something in the QtCore.

http://qt-project.org/doc/qt-4.8/eventsandfilters.html

It is most likely a synchronization issue or a memory leak issue or maybe even a memory access issue.

Memory Leak?

To rule out the memory leak issue, look at Task Manager, and watch the size of your program on the Heap. (The memory column). If it continues to grow over the whole 30 minutes, it's probably a memory leak.

Memory Access?

To see if it is a memory access issue, you might be "cleaning up" an object and then referring to it again, or referring to pointer that hasn't been instantiated yet.

To fix this, for any object created on the heap, zero it out in your constructor or even create a void init_mem() function that sets all your heap items to zero.

Then when you delete any thing make sure you set it to zero afterwards, too.

Then before accessing any of your pointers, check to make sure they are not null, and return or print an error if they are.

Synchronization Issue?

And lastly if you are having a synchronization issue, this would have to deal with any data that is accessed by multiple threads. Any data shared between the two or more threads needs to be treated as a problem area. So wrap it with something like the QMutexLocker properly or something similar. Also calls to another thread should be done using signals and slots connected over a Queued Connection, not an Auto Connection or a Direct Connection.

It sounds like if you aren't using threads, you probably should be, because of the Producer/Consumer model you have.

Debugging Techniques

Also with long running processes using logging and debug statements properly can help narrow down what is causing the problem.

Adding Qt Sources to QtCreator 2.4.1

http://qt-project.org/doc/qt-4.8/debug.html

Hope that helps.

Upvotes: 3

Related Questions