mac qt app runs from Qt Creator but crashes if macqtdeploy is used

92 Views Asked by At

I have a Qt app that for a long time I have successfully built on the Mac inside Qt Creator, then distributed by using macdeployqt then creating a .dmg file. That was on a late-2014 Mac Mini using Qt 5.15.1.

I recently upgraded to a new Mac Mini 2023 using an M2 processor. Since then I have found that the app can still be built and run successfully in Qt Creator (12.0.1), but when I build it on the command line and use macdeployqt, that version crashes in a thread-related function.

Update: see the end of this post and the notes for a fix that seems to work.

I have tried using Qt 5.15.1 and 5.15.2 and the results are the same (yes, I have tried Qt 6: see below). Here is the relevant part of the crash report:

Process:               CartoTypeMaps [14478]
Path:                  /Volumes/VOLUME/CartoTypeMaps.app/Contents/MacOS/CartoTypeMaps
Identifier:            com.yourcompany.CartoTypeMaps
Version:               ???
Code Type:             X86-64 (Translated)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2023-12-28 09:50:05.1807 +0000
OS Version:            macOS 13.5 (22G74)
Report Version:        12
Anonymous UUID:        E937E16C-6079-DC90-55E4-74D065DDB839


Time Awake Since Boot: 5300 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace SIGNAL, Code 6 Abort trap: 6
Terminating Process:   CartoTypeMaps [14478]

Application Specific Information:
abort() called


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   ???                                 0x7ff89a48a9a8 ???
1   libsystem_kernel.dylib              0x7ff80a843202 __pthread_kill + 10
2   libsystem_pthread.dylib             0x7ff80a87aee6 pthread_kill + 263
3   libsystem_c.dylib                   0x7ff80a7a1b45 abort + 123
4   libc++abi.dylib                     0x7ff80a835282 abort_message + 241
5   libc++abi.dylib                     0x7ff80a8273e1 demangling_terminate_handler() + 241
6   libobjc.A.dylib                     0x7ff80a4fba7f _objc_terminate() + 104
7   libc++abi.dylib                     0x7ff80a8346db std::__terminate(void (*)()) + 6
8   libc++abi.dylib                     0x7ff80a836fa7 __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 27
9   libc++abi.dylib                     0x7ff80a836f6e __cxa_throw + 116
10  CartoTypeMaps                          0x103068463 CartoTypeCore::CVectorTileServer::CVectorTileServer(CartoTypeCore::Framework&, unsigned long, unsigned long) + 1525

I have now tried using the latest Qt, version 6.6.1, and the problem is almost the same. The crash is still in a thread-related function. Here is the crash report for the 6.6.1 build:

Process:               CartoTypeMaps [20293]
Path:                  /Volumes/VOLUME/CartoTypeMaps.app/Contents/MacOS/CartoTypeMaps
Identifier:            com.yourcompany.CartoTypeMaps
Version:               ???
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2023-12-28 10:22:19.6461 +0000
OS Version:            macOS 13.5 (22G74)
Report Version:        12
Anonymous UUID:        E937E16C-6079-DC90-55E4-74D065DDB839


Time Awake Since Boot: 7200 seconds

System Integrity Protection: enabled

Crashed Thread:        47

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace SIGNAL, Code 6 Abort trap: 6
Terminating Process:   CartoTypeMaps [20293]

Application Specific Information:
abort() called


Thread 0::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib                 0x1aa127750 __psynch_cvwait + 8
1   libsystem_pthread.dylib                0x1aa164574 _pthread_cond_wait + 1232
2   libc++.1.dylib                         0x1aa08cef0 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3   QtCore                                 0x1033af1b4 QSemaphore::acquire(int) + 80
4   QtGui                                  0x101b022dc 0x1016a0000 + 4596444
5   QtGui                                  0x101ae452c 0x1016a0000 + 4474156
6   QtGui                                  0x1017e7800 0x1016a0000 + 1341440
7   QtGui                                  0x10180d358 0x1016a0000 + 1495896
8   QtGui                                  0x10180f844 QRasterPaintEngine::fill(QVectorPath const&, QBrush const&) + 1248

Note that the crash is exactly same in 6.6.1 for both architectures: ARM-64 and X86-64 (Translated).

I suspect that the app finds the wrong dynamic library when run from the version using macdeployqt, but I don't know what to do about that.

Following advice from Jeremy Friesner in a comment, I tried running the app from a command line to see the abort message and got this result:

./CartoTypeMaps.app/Contents/MacOS/CartoTypeMaps
QThreadPipe: Unable to create pipe: Too many open files
QEventDispatcherUNIXPrivate(): Cannot continue without a thread pipe
zsh: abort      ./CartoTypeMaps.app/Contents/MacOS/CartoTypeMaps

I have been able to fix the problem by increasing the maximum number of open files on my Mac Mini, which arrived with the rather low number of 256.

When running the app from the terminal I used the command ulimit -n 10240, which worked, but the ulimit command affects only the current process, so that didn't fix the problem for running the app by double-clicking the .dmg file and then double-clicking the app icon inside the opened disk image. To handle the latter problem, after some searching I discovered this solution:

sudo launchctl limit maxfiles 256 unlimited
sudo launchctl limit maxfiles 128000 524288

and both commands are indeed necessary.

Obviously it would be useful to know why so many files are being opened, and I'll have another look at my app; but I don't think it opens more than 40 or 50. It looks as if the limit of 256 is not for an individual app but system-wide.

I would also like to know why everything worked fine when running the app from Qt Creator, but I suspect that it increases the file limit itself for any processes it launches.

0

There are 0 best solutions below