Our app uses a number of collection views in a single iPad screen for the user to set the location of various resources. There is a main group for unassigned resources and up to 16 UICollectionView's that represent a job for the resource. The user can manage their resources by dragging a resource between any of the collection views. This generally works but periodically after dragging back and forth many times we get the following runtime exception:
Shadow insert is nil. File a bug on UICollectionView!
When I search for this error I get no results. The drag and drop implementation is as follows:
public func collectionView(_ collectionView: UICollectionView, canHandle session: UIDropSession) -> Bool {
if !singleUseCollectionViews.contains(collectionView){
return true
}
guard let containerProperties = getResourceContainer(collectionView: collectionView) else {
return false
}
return viewModel.canResourceBeDropped(containerToDropTo: containerProperties)
}
public func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal {
currentDestinationIndexPath = destinationIndexPath
// Copy is being used to add the green plus icon when user is dropping item into the other collectionview.
return UICollectionViewDropProposal(operation: .copy, intent: .insertAtDestinationIndexPath)
}
public func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) {
defer {
viewModel.isUserDraggingResource = false
}
guard let containerToDropTo = getResourceContainer(collectionView: collectionView, sectionIndex: 0) else {
print("Attempting to drop where resource cannot be dropped")
assertionFailure()
return
}
if let resourceToDrop = self.viewModel.resourceToDrop {
self.viewModel.addNewResourceToGroup(resource: resourceToDrop,
containerProperties: containerToDropTo,
userInitiated: true)
} else if self.viewModel.personnelToDrop != nil {
self.viewModel.formNewResourcesWithDroppedPersonnel(containerToDropTo: containerToDropTo)
}
resourceDropped()
}
public func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
guard viewModel.boardIsActive else {
return []
}
guard let stringData = "test".data(using: .utf8) else {
return []
}
guard let containerToDropFrom = getContainer(collectionView: collectionView, sectionIndex: indexPath.section) else {
return []
}
viewModel.prepareToDropFrom(index: indexPath.row,
containerProperties: containerToDropFrom)
let itemProvider = NSItemProvider(item: stringData as NSData, typeIdentifier: "WorksheetCell" as String)
let dragItem = UIDragItem(itemProvider: itemProvider)
session.localContext = (indexPath, collectionView)
return [dragItem]
}
public func collectionView(_ collectionView: UICollectionView, dragSessionDidEnd session: UIDragSession) {
viewModel.isUserDraggingResource = false
collectionView.endInteractiveMovement()
}
}
We see this crash in production and test on physical devices. I have yet to see it on the simulator, however under similar circumstances the simulator has simply crashed with no info in Xcode. When that happens, the following stack trace is presented by Mac OS.
Translated Report (Full Report Below)
OS Version: macOS 13.0 (22A380) Release Type: User Report Version: 104Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Triggered by Thread: 0Last Exception Backtrace: 0 CoreFoundation 0x10fa668bb __exceptionPreprocess + 226 1 libobjc.A.dylib 0x10d49fba3 objc_exception_throw + 48 2 Foundation 0x11164137c _userInfoForFileAndLine + 0 3 UIKitCore 0x124f3c65e -[_UICollectionViewDragAndDropController _beginDragAndDropInsertingItemAtIndexPath:] + 639 4 UIKitCore 0x124f3a699 -[_UICollectionViewDragAndDropController beginReorderingForItemAtIndexPath:cell:] + 281 5 UIKitCore 0x124eee108 -[UICollectionView _beginInteractiveMovementForItemAtIndexPath:] + 263 6 UIKitCore 0x124f479c9 -[_UICollectionViewDragDestinationController _reorderingDisplayLinkDidTick] + 1545 7 QuartzCore 0x10f4b200f CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 923 8 QuartzCore 0x10f5d7aa9 display_timer_callback(__CFMachPort*, void*, long, void*) + 395 9 CoreFoundation 0x10f991c9f __CFMachPortPerform + 151 10 CoreFoundation 0x10f9c6844 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 41 11 CoreFoundation 0x10f9c5d8b __CFRunLoopDoSource1 + 538 12 CoreFoundation 0x10f9c0588 __CFRunLoopRun + 2740 13 CoreFoundation 0x10f9bf6f7 CFRunLoopRunSpecific + 560 14 GraphicsServices 0x11659228a GSEventRunModal + 139 15 UIKitCore 0x1259b162b -[UIApplication _run] + 994 16 UIKitCore 0x1259b6547 UIApplicationMain + 123 17 IncidentIntelligenceSystem 0x100a568ff main + 63 (AppDelegate.swift:23) 18 dyld_sim 0x10ad082bf start_sim + 10 19 dyld 0x202a52310 start + 2432Kernel Triage: VM - pmap_enter retried due to resource shortage VM - pmap_enter retried due to resource shortage VM - pmap_enter retried due to resource shortage VM - pmap_enter retried due to resource shortage VM - pmap_enter retried due to resource shortage
Any help would be greatly appreciated.