Very often when I try to load an Entity in RealityView the system give me an error: The operation couldn’t be completed. (Swift.CancellationError error 1.)
RealityView { content in
do {
let scene = try await Entity(named: "Test_Scene", in: realityKitContentBundle)
content.add(scene)
} catch {
debugPrint("error loading scene", error.localizedDescription.debugDescription)
}
}
The scene I created contain a basic square
This is the main file
struct first_app_by_appleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}.windowStyle(.volumetric)
}
}
and inside info.plist file I setup UIApplicationPreferredDefaultSceneSessionRole with UIWindowSceneSessionRoleVolumetricApplication
I think that could be a bug of the system but I'm not surprised since it's the first beta. If so, do you know any workarounds?
This issue usually happens when the RealityView deinits before its tasks are completed. A solution to this issue is to handle the CancellationError like this:
RealityView { content in
do {
let scene = try await Entity(named: "Test_Scene", in: realityKitContentBundle)
content.add(scene)
} catch is CancellationError { /*ignore*/
} catch {
assertionFailure("\(error.localizedDescription)")
}
}