I have a SceneView from a mobile scene package in a swiftUI app. When I add operational layers and rotate the device to landscape then back to portrait, I am consistently getting a crash with the following message:
I have updated to 200.2 but still the error persists. I also get this error occasionally when entering background mode from the sceneView. Once again if I remove operational layers or select another tab in the navigationSplitView then there is no error.
This error only appears if I have an operational layer added.
enum Detail: Hashable {
case geography
}
struct ContentView: View {
@State private var selection: Detail?
var body: some View {
NavigationSplitView() {
List(selection: $selection) {
NavigationLink(value: Detail.geography) {
HStack(spacing: 12) {
Image(systemName: "globe")
Text("Geography")
}
}
}
} detail: {
switch selection {
case .geography:
GeographyView()
default:
EmptyView()
}
}
}
}
struct GeographyView: View {
@State private var scene = Scene()
@State private var mobileScenePackage: MobileScenePackage!
@State var camera: Camera? = Camera(location: Point(x: 113.915001, y: 22.308901, z: 4_953_394, spatialReference: .wgs84), heading: 360.0, pitch: 0.0, roll: 0)
@State var presentPositionOverlay: GraphicsOverlay?
var mapOverlays: [GraphicsOverlay] {
var overlays: [GraphicsOverlay] = []
if presentPositionOverlay != nil {
overlays.append(presentPositionOverlay!)
}
return overlays
}
private func loadMobileScenePackage() async throws {
let sceneURL = Bundle.main.url(forResource: "satteliteImageryScene", withExtension: "mspk")!
self.mobileScenePackage = MobileScenePackage(fileURL: sceneURL)
try await mobileScenePackage.load()
guard let scene = mobileScenePackage.scenes.first else { return }
let x = 113.915001
let y = 22.308901
scene.initialViewpoint = Viewpoint(latitude: y, longitude: x, scale: 4_953_394)
setPresentPositionOverlay(x: x, y: y)
self.scene = scene
}
func setPresentPositionOverlay(x: Double, y: Double) {
let overlay = GraphicsOverlay()
let location = Point(x: x, y: y, spatialReference: .wgs84)
let backgroundSymbol = SimpleMarkerSymbol(style: SimpleMarkerSymbol.Style.circle, color: .white, size: 14)
let markerSymbol = SimpleMarkerSymbol(style: SimpleMarkerSymbol.Style.circle, color: .blue, size: 10)
let symbol = CompositeSymbol(symbols: [backgroundSymbol, markerSymbol])
let graphic = Graphic(geometry: location, symbol: symbol)
graphic.zIndex = 100
overlay.addGraphic(graphic)
presentPositionOverlay = overlay
}
// MARK: - Body
var body: some View {
NavigationStack {
SceneViewReader { sceneView in
ZStack {
SceneView(scene: scene, camera: $camera, graphicsOverlays: mapOverlays)
.task {
do {
try await loadMobileScenePackage()
} catch {
print(error)
}
}
}
}
}
}
}