Custom Component causing exc_bad_access

Hello,

After watching the Work with Reality Composer Pro content in Xcode, I had created the following custom component.

public struct TestComponent : Component, Codable{
    public var text : String = "helloWorld"
    public init() {}
}

I had registered the custom component as suggested in App.init function

init() {
RealityKitContent.TestComponent.registerComponent()
}

The custom component is decoded and realityView shows the sphere, when I load the "Scene" from realityKitContent bundle.

But if I export the scene to a separate file named "test_scene.usdz" on disk and shared to the simulator and then trying to load it load in reality view causes

EXC_BAD_ACCESS #0 0x0000000194c8d508 in Swift._StringObject.getSharedUTF8Start() -> Swift.UnsafePointer<Swift.UInt8> ()

Printing the loaded entity, shows the customComponent but when trying to load in show realityview , crashes the app immediately. Is there a way to fix it?

Answered by mithun_venkatesan in 825042022

Finally I was able to figure out how to save custom components and load them from file system. The solution is save it as reality file and not usdz. This is kinda a round about way as Reality Composer pro doesn't support exporting files directly to reality file. It would be great if this functionality is added to Reality Composer pro.

Hi @mithun_venkatesan,

First thing that comes to mind is that the type TestComponent is unknown to this application holding the RealityView that the "test_scene.usdz" was shared to.

If that is not the case and you are certain the type is there then I'd say this would be a great feedback. The more detail you can provide in the feedback the better, including a simplified bit of code that demonstrates the problem. Thanks!

An Overview of RealityKit Codable Components:

Since "git.rwth-aachen.de" is not in the permitted domain list, I used the inline codes for links.

Source Repo link : https://git.rwth-aachen.de/apple-realitykit-usdz/usdz_files

The repository explores the inconsistencies with custom components when loading a scene exported as usdz from file system(here after refered as exported file) and loading the scene directly from the bundle(here after refered as internal file). The expected behaviour is that after parsing both the external file and internal file both should have the same values for the custom components.

Reality Composer Pro supports a small set of primitive data types which provides the functionality to create and modifying the Scenes with no explicit coding requirments. The following code block shows the all possible primitive codable compontents.


public struct TestComponentBool : Component, Codable {
    public var someBool : Bool = false
    public init() {}
}

public struct TestComponentFloat : Component, Codable {
    public var someFloatNumber : Float = 0
    public init() {}
}

public struct TestComponentInt : Component, Codable {
    public var someIntNumber : Int = 0
    public init() {}
}

public struct TestComponentUint : Component, Codable {
    public var someIntNumber : UInt = 0
    public init() {}
}

public struct TestComponentString : Component, Codable {
    public var someString : String = "Hello world !"
    public init() {}
}

public struct TestComponentSimdFloat : Component, Codable {
    public var someFloatArray : SIMD3<Float> = [0,0,0]
    public init() {}
}

public struct TestComponentChoice : Component, Codable {
    
    public enum SomeChoice : String, Codable{
        case choice1, choice2, choice3
    }
    
    public var someChoice : SomeChoice = .choice1
    
    public init() {}
}

To see the implementation of the above components, check the RealityKitContent package in CustomComponentsParser available in https://git.rwth-aachen.de/apple-realitykit-usdz/customcomponentsparser/-/tree/main/Packages/RealityKitContent.

When exporting a scene with the all above components to a seperate .usdz file, and then loading it in an app has custom components registered, the values stored in these components those match the value when it was exported, leading to inconsistencies and EXC_BAD_ACCESS in the worst case when the component contains a String type.

To reproduce the error,

  1. Export Scene.usda in to RealityKitContent package with Reality Composer Pro and share to the simulator. Alternatively the usdz file in the source repository https://git.rwth-aachen.de/apple-realitykit-usdz/usdz_files can be directly shared to the simulator.
  2. Build and install the app in the link https://git.rwth-aachen.de/apple-realitykit-usdz/customcomponentsparser/.
  3. Open the CustomComponentsParser app
  4. Click on Load from internal storage to load the Scene entity.
  5. Click on Import usdz file and select the exported file shared to the simulator.

@Vision Pro Engineer would like to know if there are any updates on this.

Accepted Answer

Finally I was able to figure out how to save custom components and load them from file system. The solution is save it as reality file and not usdz. This is kinda a round about way as Reality Composer pro doesn't support exporting files directly to reality file. It would be great if this functionality is added to Reality Composer pro.

Custom Component causing exc_bad_access
 
 
Q