Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt application unexpectedly crashes after a while due to access violation error at iosfwd



  • Hello , even if Qt is quite promising , i am still frustrated sometimes with the undefined behavior. Today out of the blue my Qt GUI app unexpectedly crashed after a while. The debugging triggers an access violation code and the info says that the problem occurs at iosfwd at function std::char_traits<char>::length. Really , i cant follow these whatever unexpected errors.... With all respect, i appeal to all Qt experts out there, could you please help me with this crap ?



  • @xenovas said in Qt application unexpectedly crashes after a while due to access violation error at iosfwd:

    info says that the problem occurs at iosfwd at function std::char_traits<char>::length

    Can you post the complete stack trace instead of just the topmost item?


  • Moderators

    hi @xenovas

    access violation errors are hardly Qt's or a c++ fault.
    It's usually a result of accessing an array / list with an index that is greater than the actual length. Or trying to access a class instance that is no longer valid.

    C++ is a rather low-level language so you actually have to manage lifetimes and access to Containers yourself.

    The Qt-Libary actually does a lot of comfort stuff for you, that reduces such kind of errors, but in the end, it's up to you.

    From the error code you posted I would say you try to access a char of string via index, and the string is not long enough.

    You would have to post the actual stack trace here, for us to say more about it.



  •    0  Id: 12cc.1a68 Suspend: 1 Teb: 00000097`474dc000 Unfrozen
    Child-SP          RetAddr           Call Site
    00000097`473bc0a8 00007ffd`fabc031d win32u!NtUserMsgWaitForMultipleObjectsEx+0x14
    00000097`473bc0b0 00000000`555a5ab8 USER32!MsgWaitForMultipleObjectsEx+0x9d
    *** WARNING: Unable to verify checksum for C:\Qt\5.10.0\msvc2017_64\plugins\platforms\qwindowsd.dll
    00000097`473bc0f0 00007ffd`af8008f4 Qt5Cored!QEventDispatcherWin32::processEvents(class QFlags<enum QEventLoop::ProcessEventsFlag> flags = class QFlags<enum QEventLoop::ProcessEventsFlag>)+0x678 [c:\users\qt\work\qt\qtbase\src\corelib\kernel\qeventdispatcher_win.cpp @ 646]
    00000097`473bf290 00000000`554e78c8 qwindowsd!QWindowsGuiEventDispatcher::processEvents(class QFlags<enum QEventLoop::ProcessEventsFlag> flags = class QFlags<enum QEventLoop::ProcessEventsFlag>)+0x34 [c:\users\qt\work\qt\qtbase\src\platformsupport\eventdispatchers\qwindowsguieventdispatcher.cpp @ 74]
    00000097`473bf2d0 00000000`554e7b0e Qt5Cored!QEventLoop::processEvents(class QFlags<enum QEventLoop::ProcessEventsFlag> flags = class QFlags<enum QEventLoop::ProcessEventsFlag>)+0x68 [c:\users\qt\work\qt\qtbase\src\corelib\kernel\qeventloop.cpp @ 135]
    00000097`473bf310 00000000`554eaf5f Qt5Cored!QEventLoop::exec(class QFlags<enum QEventLoop::ProcessEventsFlag> flags = class QFlags<enum QEventLoop::ProcessEventsFlag>)+0x18e [c:\users\qt\work\qt\qtbase\src\corelib\kernel\qeventloop.cpp @ 212]
    *** WARNING: Unable to verify checksum for C:\Qt\5.10.0\msvc2017_64\bin\Qt5Guid.dll
    00000097`473bf3c0 00007ffd`93745cb8 Qt5Cored!QCoreApplication::exec(void)+0x15f [c:\users\qt\work\qt\qtbase\src\corelib\kernel\qcoreapplication.cpp @ 1332]
    *** WARNING: Unable to verify checksum for C:\Qt\5.10.0\msvc2017_64\bin\Qt5Widgetsd.dll
    00000097`473bf470 00000000`55dc522a Qt5Guid!QGuiApplication::exec(void)+0x18 [c:\users\qt\work\qt\qtbase\src\gui\kernel\qguiapplication.cpp @ 1688]
    00000097`473bf4a0 00007ff6`987c6475 Qt5Widgetsd!QApplication::exec(void)+0xa [c:\users\qt\work\qt\qtbase\src\widgets\kernel\qapplication.cpp @ 2918]
    00000097`473bf4d0 00007ff6`98803d9d testservercnc!main(int argc = 0n1, char ** argv = 0x000001dd`d1cb2d40)+0x95 [c:\users\xxxxxxxxxxxxxx\documents\qt_projects\testservercnc\main.cpp @ 14]
    00000097`473bf610 00007ff6`9880220d testservercnc!WinMain(struct HINSTANCE__ * __formal = 0x00007ff6`987c0000, struct HINSTANCE__ * __formal = 0x00000000`00000000, char * __formal = 0x000001dd`d1ca90f2 "", int __formal = 0n10)+0xed [c:\users\qt\work\qt\qtbase\src\winmain\qtmain_win.cpp @ 104]
    00000097`473bf690 00007ff6`988020fe testservercnc!invoke_main(void)+0x2d [d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 107]
    00000097`473bf6d0 00007ff6`98801fbe testservercnc!__scrt_common_main_seh(void)+0x12e [d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288]
    00000097`473bf740 00007ff6`98802299 testservercnc!__scrt_common_main(void)+0xe [d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 331]
    00000097`473bf770 00007ffd`fa0a3034 testservercnc!WinMainCRTStartup(void)+0x9 [d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_winmain.cpp @ 17]
    00000097`473bf7a0 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`473bf7d0 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    
       1  Id: 12cc.1f64 Suspend: 1 Teb: 00000097`474de000 Unfrozen
    Child-SP          RetAddr           Call Site
    00000097`476ff498 00007ffd`fb506866 ntdll!ZwWaitForWorkViaWorkerFactory+0x14
    00000097`476ff4a0 00007ffd`fa0a3034 ntdll!RtlReleaseSRWLockExclusive+0x576
    00000097`476ff790 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`476ff7c0 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    
       2  Id: 12cc.fe4 Suspend: 1 Teb: 00000097`474e0000 Unfrozen
    Child-SP          RetAddr           Call Site
    00000097`477ffba8 00007ffd`fb506866 ntdll!ZwWaitForWorkViaWorkerFactory+0x14
    00000097`477ffbb0 00007ffd`fa0a3034 ntdll!RtlReleaseSRWLockExclusive+0x576
    00000097`477ffea0 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`477ffed0 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    
       3  Id: 12cc.2510 Suspend: 1 Teb: 00000097`474e2000 Unfrozen
    Child-SP          RetAddr           Call Site
    00000097`478ff4f8 00007ffd`fb506866 ntdll!ZwWaitForWorkViaWorkerFactory+0x14
    00000097`478ff500 00007ffd`fa0a3034 ntdll!RtlReleaseSRWLockExclusive+0x576
    00000097`478ff7f0 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`478ff820 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    
       4  Id: 12cc.4640 Suspend: 1 Teb: 00000097`474e4000 Unfrozen
    Child-SP          RetAddr           Call Site
    00000097`479ffc08 00007ffd`fb506866 ntdll!ZwWaitForWorkViaWorkerFactory+0x14
    00000097`479ffc10 00007ffd`fa0a3034 ntdll!RtlReleaseSRWLockExclusive+0x576
    00000097`479fff00 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`479fff30 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    
    #  5  Id: 12cc.4834 Suspend: 1 Teb: 00000097`474e6000 Unfrozen "QThread"
    Child-SP          RetAddr           Call Site
    00000097`47aff408 00007ff6`987cf833 ucrtbased!strlen+0x31
    00000097`47aff410 00007ff6`987ceec8 testservercnc!std::char_traits<char>::length(char * _First = 0x00000000`00000000 "")+0x13 [c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\iosfwd @ 466]
    00000097`47aff440 00007ff6`987cc69b testservercnc!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(char * _Ptr = 0x00000000`00000000 "")+0x18 [c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xstring @ 2676]
    00000097`47aff470 00007ff6`987cb5b4 testservercnc!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >(char * _Ptr = 0x00000000`00000000 "")+0x3b [c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xstring @ 2185]
    00000097`47aff4b0 00007ff6`987e579c testservercnc!server::socketConnect(void)+0x4c4 [c:\users\xxxxxxxxxxxxxx\documents\qt_projects\testservercnc\server.cpp @ 156]
    00000097`47aff7a0 00007ff6`987fe616 testservercnc!Worker::doWork(void)+0x38c [c:\users\xxxxxxxxxxxxxx\documents\qt_projects\testservercnc\worker.cpp @ 85]
    00000097`47aff9e0 00000000`5553fec8 testservercnc!Worker::qt_static_metacall(class QObject * _o = 0x000001dd`d5276690, QMetaObject::Call _c = InvokeMetaMethod (0n0), int _id = 0n3, void ** _a = 0x00000097`47affc90)+0x156 [c:\users\xxxxxxxxxxxxxx\documents\qt_projects\build-testservercnc-desktop_qt_5_10_0_msvc2017_64bit-debug\debug\moc_worker.cpp @ 97]
    00000097`47affa70 00000000`5553f618 Qt5Cored!QMetaObject::activate(class QObject * sender = 0x000001dd`d527fac0, int signalOffset = 0n3, int local_signal_index = 0n0, void ** argv = 0x00000097`47affc90)+0x898 [c:\users\qt\work\qt\qtbase\src\corelib\kernel\qobject.cpp @ 3768]
    00000097`47affc40 00000000`55121ff9 Qt5Cored!QMetaObject::activate(class QObject * sender = 0x000001dd`d527fac0, struct QMetaObject * m = 0x00000000`55770cc0, int local_signal_index = 0n0, void ** argv = 0x00000097`47affc90)+0x38 [c:\users\qt\work\qt\qtbase\src\corelib\kernel\qobject.cpp @ 3629]
    00000097`47affc70 00000000`5512f9d6 Qt5Cored!QThread::started(struct QThread::QPrivateSignal _t1 = struct QThread::QPrivateSignal)+0x39 [c:\users\qt\work\qt\qtbase\src\corelib\.moc\debug\moc_qthread.cpp @ 159]
    00000097`47affcb0 00007ffd`fa0a3034 Qt5Cored!QThreadPrivate::start(void * arg = 0x000001dd`d527fac0)+0x186 [c:\users\qt\work\qt\qtbase\src\corelib\thread\qthread_win.cpp @ 376]
    00000097`47affd30 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`47affd60 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    
       6  Id: 12cc.4838 Suspend: 1 Teb: 00000097`474e8000 Unfrozen "Thread (pooled)"
    Child-SP          RetAddr           Call Site
    00000097`47bff548 00007ffd`f8525e9a ntdll!NtDelayExecution+0x14
    00000097`47bff550 00000000`5512f642 KERNELBASE!SleepEx+0x9a
    00000097`47bff5f0 00007ff6`987e7ec6 Qt5Cored!QThread::msleep(unsigned long msecs = 0x1f4)+0x12 [c:\users\qt\work\qt\qtbase\src\corelib\thread\qthread_win.cpp @ 458]
    00000097`47bff620 00007ff6`987ec6c1 testservercnc!ConnectionUnit::newPoll(int recv = 0n0)+0x7a6 [c:\users\xxxxxxxxxxxxxx\documents\qt_projects\testservercnc\connectionunit.cpp @ 232]
    00000097`47bff940 00007ff6`987f033a testservercnc!<lambda_cf0a3a32572377455d796e14f7df8d37>::operator()(void)+0x21 [c:\users\xxxxxxxxxxxxxx\documents\qt_projects\testservercnc\connectionunit.cpp @ 62]
    00000097`47bff970 00007ff6`987f02c2 testservercnc!QtConcurrent::StoredFunctorCall0<void,<lambda_cf0a3a32572377455d796e14f7df8d37> >::runFunctor(void)+0x1a [c:\qt\5.10.0\msvc2017_64\include\qtconcurrent\qtconcurrentstoredfunctioncall.h @ 70]
    00000097`47bff9a0 00000000`5512767b testservercnc!QtConcurrent::RunFunctionTask<void>::run(void)+0x62 [c:\qt\5.10.0\msvc2017_64\include\qtconcurrent\qtconcurrentrunbase.h @ 136]
    00000097`47bffa10 00000000`5512f9ef Qt5Cored!QThreadPoolThread::run(void)+0x8b [c:\users\qt\work\qt\qtbase\src\corelib\thread\qthreadpool.cpp @ 101]
    00000097`47bffad0 00007ffd`fa0a3034 Qt5Cored!QThreadPrivate::start(void * arg = 0x000001dd`d5296670)+0x19f [c:\users\qt\work\qt\qtbase\src\corelib\thread\qthread_win.cpp @ 378]
    00000097`47bffb50 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`47bffb80 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    
       7  Id: 12cc.4840 Suspend: 1 Teb: 00000097`474ea000 Unfrozen
    Child-SP          RetAddr           Call Site
    00000097`47cff548 00007ffd`fb506866 ntdll!ZwWaitForWorkViaWorkerFactory+0x14
    00000097`47cff550 00007ffd`fa0a3034 ntdll!RtlReleaseSRWLockExclusive+0x576
    00000097`47cff840 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`47cff870 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    
       8  Id: 12cc.4844 Suspend: 1 Teb: 00000097`474ec000 Unfrozen
    Child-SP          RetAddr           Call Site
    00000097`47dff4b8 00007ffd`fb506866 ntdll!ZwWaitForWorkViaWorkerFactory+0x14
    00000097`47dff4c0 00007ffd`fa0a3034 ntdll!RtlReleaseSRWLockExclusive+0x576
    00000097`47dff7b0 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`47dff7e0 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    
       9  Id: 12cc.4848 Suspend: 1 Teb: 00000097`474ee000 Unfrozen
    Child-SP          RetAddr           Call Site
    00000097`47eff4f8 00007ffd`f8526099 ntdll!NtWaitForMultipleObjects+0x14
    *** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\System32\combase.dll - 
    00000097`47eff500 00007ffd`fad73e77 KERNELBASE!WaitForMultipleObjectsEx+0xf9
    00000097`47eff800 00007ffd`fadf2d30 combase!CoGetTreatAsClass+0xd5f7
    00000097`47effa90 00007ffd`fad712d1 combase!CoDisableCallCancellation+0x110
    00000097`47effae0 00007ffd`fadf65dc combase!CoGetTreatAsClass+0xaa51
    00000097`47effb40 00007ffd`fa0a3034 combase!CoRegisterPSClsid+0x51c
    00000097`47effb70 00007ffd`fb553691 KERNEL32!BaseThreadInitThunk+0x14
    00000097`47effba0 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    


  • Hello @J-Hilk ,

    I'm not a very experienced developer, nevertheless its clear what you are saying here but the program crashes when QThread invokes currentThread() where the inner functionality is not controlable by my code thus it is not my responsibility to manage the memory allocation of a char * or to manage the actual list index ...i suppose.... My code was working very well yesterday except some warnings that were manageable.



  • 0_1548674832966_debug.PNG


  • Moderators

    @xenovas

    even so, the debugger crashes you inside code, that's part of a library it's usually (99% of the time) part of your own source code that causes the crash.
    Multi threading makes this a bit more difficult to see/debug on a first glance.

    I see, that you use QtCreator for your development, you can trace the crash back wards in there to the last line/call that is inside your own source files, that should make things a bit clearer.

    In the screenshot, step back the levels in the bottom left window until you find in the file column where you find the first appearance of your own source code. From the stack trace I would say it's either server.cpp or worker.cpp



  • @J-Hilk i will check thank you



  • @J-Hilk yeap you were right it was a null ptr dereference issue. I was trying to feed a std::map with a char * without checking if the allocated memory was returning a NULL, thus it was crashing my app.
    Thank you for your help !


  • Moderators

    @xenovas
    I'm glad it's now working for you ;-), happy coding!

    Don't forget to set the topic to solved.


Log in to reply