SwiftUI and MapKit error, thread 1

Greetings, in the @main file I keep getting this error, "Thread 1: "-[MTLSimHeap protectionOptions]: unrecognized selector sent to instance 0x600001864d20"" I have no idea what's causing it and how to solve it. Here is the code:

import SwiftUI
import MapKit

struct ContentView: View {

@StateObject private var viewModel = ContentViewModel()

   var body: some View {
   
    ZStack {

       Map(coordinateRegion: $viewModel.region, showsUserLocation: true)
                .accentColor(.blue)
                .onAppear{

                viewModel.checkIfLocationServicesEnabled()

                    

                }

            

        }

    }

}



struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}



final class ContentViewModel: NSObject, ObservableObject, CLLocationManagerDelegate{

    

    var locationManager: CLLocationManager?

    

    @Published var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.331516, longitude: -121.891054), span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

    

    func checkIfLocationServicesEnabled() {

        if CLLocationManager.locationServicesEnabled() {

            locationManager = CLLocationManager()

            locationManager!.delegate = self

            

        } else {

            print("show alert: location is off.")

        }

    }

  private func checkLocationAuthorization() {

      

        guard let locationManager = locationManager else { return }

        

        switch locationManager.authorizationStatus {

            

            case .notDetermined:

            locationManager.requestWhenInUseAuthorization()

            

            case .restricted:

            print("Your Location is restricted likely due to parental controls.")

            case .denied:

            print("You denied this app location permission, go to the settings to change it.")

            case .authorizedAlways, .authorizedWhenInUse:

            region = MKCoordinateRegion(center: locationManager.location!.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

            @unknown default:

            break

        }

    }

    

    func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {

        checkLocationAuthorization()

    }

}

The @main file:

import SwiftUI



@main

struct MyApp: App {

    

    

    var body: some Scene {

        WindowGroup {

            ContentView()

        }

    }

}

Error may show in Main but be occurring elsewhere.

Have you defined the authorisation keys in info.plist ?

SwiftUI and MapKit error, thread 1
 
 
Q