'Xcode crash report: CoreAutoLayout: _AssertAutoLayoutOnAllowedThreadsOnly

Xcode has reported this crash, I think the reason is that something was running out of the main thread, but it shouldn't. However, I can't find out what.
Here is how the crash report(exception backtrace) looks like:

1

And here is the full crash report for the 10th thread, which looks like to be the reason of crash:

Thread 10 Crashed:
    0   libsystem_kernel.dylib          0x00000001afbdf414 __pthread_kill + 8
    1   libsystem_pthread.dylib         0x00000001cc0f7b40 pthread_kill + 272 (pthread.c:1388)
    2   libsystem_c.dylib               0x000000018c004bf4 __abort + 116 (abort.c:147)
    3   libsystem_c.dylib               0x000000018c004b80 abort + 116 (abort.c:118)
    4   libc++abi.dylib                 0x000000019733ccf8 abort_message + 132 (abort_message.cpp:76)
    5   libc++abi.dylib                 0x000000019732de4c demangling_terminate_handler() + 308 (cxa_default_handlers.cpp:67)
    6   libobjc.A.dylib                 0x0000000197236f64 _objc_terminate() + 144 (objc-exception.mm:701)
    7   App - Production            0x0000000104b03714 CLSTerminateHandler() + 352 (CLSException.mm:311)
    8   libc++abi.dylib                 0x000000019733c0e0 std::__terminate(void (*)()) + 20 (cxa_handlers.cpp:59)
    9   libc++abi.dylib                 0x000000019733c06c std::terminate() + 44 (cxa_handlers.cpp:88)
    10  libdispatch.dylib               0x00000001828d4dc4 _dispatch_client_callout + 40 (object.m:562)
    11  libdispatch.dylib               0x00000001828dc10c _dispatch_lane_serial_drain + 580 (inline_internal.h:2548)
    12  libdispatch.dylib               0x00000001828dcc5c _dispatch_lane_invoke + 408 (queue.c:3862)
    13  libdispatch.dylib               0x00000001828e6d78 _dispatch_workloop_worker_thread + 708 (queue.c:6601)
    14  libsystem_pthread.dylib         0x00000001cc0f8804 _pthread_wqthread + 276 (pthread.c:2206)
    15  libsystem_pthread.dylib         0x00000001cc0ff75c start_wqthread + 8

Here is the code of the reported method:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        picker.dismiss(animated: true) { self.view.controlDefaultLoadingIndicator(willAnimate: false) }
        
        //checking media type
        guard let mediaType = info[UIImagePickerControllerMediaType] as? String else { return }
        
        
        // Video media type
        if mediaType == kUTTypeMovie as String {
            guard let url = info[UIImagePickerControllerMediaURL] as? URL, UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(url.path) else { return }
            let tempURL = createTemporaryURLforFile(url: url)
            encodeVideoMP4(videoUrl: tempURL) { videoMp4Url in
                guard let videoData = try? Data(contentsOf: tempURL) else {
                    self.showToastMessage(message: "Video conversion error occured. Please try again")
                    return
                }
                
                let videoDataSize = videoData.count
                let videoFileName = "\(Date.getStringCurrentDate()).\(FileType.mp4)"
                let videoMimeType = FileMimeTypes[FileType.mp4.rawValue]
                
                self.attemptFileUpload(folderId: self._folderIdToLoad, andFileName: videoFileName, fileSize: videoDataSize, isEncrypted: self.encrypted, dataToUpload: videoData, mimeType: videoMimeType, completed: { _ in
                    self.showToastMessage(message: ApplicationStrings.toastMessageFileUploaded)
                    self.resetOffserAndUpdateDirTime()
                    self.triggerDocumentsLoad()
                })
            }
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source