MapKit, Thread 1: signal SIGABRT problem

Hello,

I am needing help in solving my “Thread 1: signal SIGABRT” problem. Also got this also:

-[MTLDebugDevice notifyExternalReferencesNonZeroOnDealloc:]:2885: failed assertion `The following Metal object is being destroyed while still required to be alive by the command buffer 0x7fa837011400 (label: <no label set>):
<MTLToolsObject: 0x7fa83317d160> -> <MTLSimTexture: 0x7fa8331dd4a0>
    label = CAMetalLayer Display Drawable 
    textureType = MTLTextureType2D 
    pixelFormat = MTLPixelFormatBGRA8Unorm_sRGB 
    decompressedPixelFormat = MTLPixelFormatBGRA8Unorm_sRGB 
    width = 1170 
    height = 528 
    depth = 1 
    arrayLength = 1 
    mipmapLevelCount = 1 
    sampleCount = 1 
    cpuCacheMode = MTLCPUCacheModeDefaultCache 
    storageMode = MTLStorageModeShared 
    hazardTrackingMode = MTLHazardTrackingModeTracked 
    resourceOptions = MTLResourceCPUCacheModeDefaultCache MTLResourceStorageModeShared MTLResourceHazardTrackingModeTracked  
    usage = MTLTextureUsageShaderRead MTLTextureUsageShaderWrite MTLTextureUsageRenderTarget MTLTextureUsagePixelFormatView 
    shareable = 0 
    framebufferOnly = 0 
    swizzle = [MTLTextureSwizzleRed, MTLTextureSwizzleGreen, MTLTextureSwizzleBlue, MTLTextureSwizzleAlpha] 
    parentTexture = <null> 
    parentRelativeLevel = 0 
    parentRelativeSlice = 0 
    buffer = <null> 
    bufferOffset = 0 
    bufferBytesPerRow = 0 
    allowGPUOptimizedContents = YES'
CoreSimulator 857.7 - Device: iPhone 14 (4DF2482C-A052-427B-8452-2B18F0D58AB0) - Runtime: iOS 16.0 (20A360) - DeviceType: iPhone 14

This video will help illustrate my problem: MapKit Launcher - YouTube

 @IBAction func showMeWhere(_ sender: Any)
        {
            DispatchQueue.global(qos: .background).async {
                //Defining destination
                let latitude:CLLocationDegrees = self.deliveryOffer!.fields.latitude.doubleValue
                let longitude:CLLocationDegrees = self.deliveryOffer!.fields.longitude.doubleValue
                
                let regionDistance: CLLocationDistance = 1000;
                let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
                let regionSpan = MKCoordinateRegion(center: coordinates, latitudinalMeters: regionDistance, longitudinalMeters: regionDistance)
                
                let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)]
                
                let placemark = MKPlacemark(coordinate: coordinates)
                let mapItem = MKMapItem(placemark: placemark)
                mapItem.name = "Destination"
                mapItem.openInMaps(launchOptions: options)
                
            }
            
        }

SIGABRT is most often caused by a disconnected IBOutlet or IBAction from Storyboard to the relevant ViewController. Check that you have not renamed an IBOutlet or an IBAction and you have a remnant connection still in Storyboard that was lost during the renaming process.

Select the Storyboard ViewController where you are having issues and open the Connections Inspector on the right Xcode Inspector panel and look for any connections that have an Amber triangle against the outlet as in the sample image.

Resolve it by deleting the connection in storyboard (tap on the x to the left of the name of the outlet where the amber triangle exists) and create a new connection from storyboard to the ViewController.

My app still crashes when I launch the map like in my video: MapKit Launcher - YouTube
I wonder if it has to do with dispatch queues if it is, I’m not all that familiar with them. I’d appreciate some assistance.

Without code it’s impossible to know what the issue is beyond what I previously suggested.

Here is the code where that MapLauncher code and button exists:

import UIKit
import MapKit

class ArrivedViewController: UIViewController, MKMapViewDelegate {
    
    
    @IBOutlet var pickUpLocation: MKMapView!
    
    var quote: Quote?
    var unit: String!
    var street: String!
    var city: String!
    var state: String!
    var postalCode: String!
    var business: String!
    

    @IBOutlet var MapLauncher: UIButton!
    @IBOutlet var businessAddress: UILabel!
    @IBOutlet var businessName: UILabel!
    
    @IBOutlet var instructionsView: UITextView!
    
        override func viewDidLoad() {
            super.viewDidLoad()
            
            DispatchQueue.main.async {
                self.parseJSON()
            }
            
        }
    
        // JSON
        private func parseJSON() {
            // Make a path to the data.json file.
            guard let path = Bundle.main.path(forResource: "Quote", ofType: "json") else {
                return } // forResource: is the file name, ofType: is the file extention
            // Pass in the path which is a string
            let url = URL(fileURLWithPath: path)
            //            var deliveryOffer: DeliveryOffer? // For testing
            // Access the content of the URL and it is throw, so put it in a do-catch method and try
            do {
                let jsonData = try Data(contentsOf: url)
                quote = try JSONDecoder().decode(Quote.self, from: jsonData)
                
                
                unit = quote?.pickup.unit
                street = quote?.pickup.street
                city = quote?.pickup.city
                state = quote?.pickup.state
                postalCode = quote?.pickup.postalCode
                business = quote?.brandName
                
                businessAddress.text =  street + " " + "Unit " + unit + " " + "\n" + city + ", " + state + "\n" + postalCode
                businessName.text = "   " + business
                instructionsView.text = quote?.pickup.instructions
                
                // Restaurant location
                let businessLocation = CLLocation(latitude: quote!.pickup.latitude, longitude: quote!.pickup.longitude)
                
                let regionRadius: CLLocationDistance = 50.0
                let region =  MKCoordinateRegion(center: businessLocation.coordinate, latitudinalMeters: regionRadius, longitudinalMeters: regionRadius)
                pickUpLocation.setRegion(region, animated: true)
                pickUpLocation.delegate = self
           
                
                // For testing
                if let quote = quote {
                    print(quote)
                }
                else {
                    print("Failed to parse")
                }
                return
            }
            catch {
                print("Error: \(error)")
            }
            
            
        }
        
    @IBAction func MapLauncher(_ sender: UIButton) {
        
        DispatchQueue.global(qos: .background).async {
            self.mapLauncher()
        }

}


func mapLauncher(){
    
    //Defining destination
let latitude:CLLocationDegrees = quote!.pickup.latitude
let longitude:CLLocationDegrees = quote!.pickup.longitude
    
    let regionDistance: CLLocationDistance = 1000;
    let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
    let regionSpan = MKCoordinateRegion(center: coordinates, latitudinalMeters: regionDistance, longitudinalMeters: regionDistance)
    
    let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)]
    
    let placemark = MKPlacemark(coordinate: coordinates)
    let mapItem = MKMapItem(placemark: placemark)
    mapItem.name = "Destination"
    mapItem.openInMaps(launchOptions: options)
}
}

Hi Gilbert

You should place some breakpoints in your code inside your mapLauncher() function to see what is being set each time to run the App. If it works sometimes and not others then you need to know that each time you execute mapLauncher() that the values you are dealing with make sense.

1 Like

Ok, I just realized that it crashes only when my app is in a “background” state. So in my code how might this be solved?

@coder3000

Why are you launching Maps in the background?
Is it necessary to launch the Maps in the background?