Creating CHHapticPatternPlayer with AudioCustom Event crashes

Hello everyone,

I’m experiencing occasional crashes in my app related to the Core Haptics framework, specifically when creating haptic pattern players. The crashes are intermittent and not easily reproducible, so I’m hoping to get some guidance on what might be causing them.

It's seems it's connected to Audio Resource I'm using within AHAP file.

Setup:

I use AVAudioSession and AVAudioEngine to record and play continuous audio. After activating the audio session and setting up the audio engine, I initialize the CHHapticEngine as follows:

 let engine = try CHHapticEngine(audioSession: .sharedInstance())
...
 try engine?.start()
        
 // Recreate all haptic pattern players you had created.
 let pattern = createPatternFromAHAP(Pattern.thinking.rawValue)!
        
 thinkingHapticPlayer = try? engine?.makePlayer(with: pattern)
// Repeat for other players...

AHAP file:

 "Pattern":
    [
      ... haptic events
       {
            "Event":
            {
                "Time": 0.0,
                "EventType": "AudioCustom",
                "EventWaveformPath": "voice.chat.thinking.mp3",
                "EventParameters":
                [
                    { "ParameterID": "AudioVolume", "ParameterValue": 0.7 }
                ]
            }
        }
]

I’m receiving the following crash report:

Crashed: com.apple.main-thread
EXC_BREAKPOINT 0x00000001ba525c68
0
CoreHaptics
+[CHHapticEngine(CHHapticEngineInternal) doRegisterAudioResource:options:fromPattern:player:error:].cold.1 + 104
1
CoreHaptics
+[CHHapticEngine(CHHapticEngineInternal) doRegisterAudioResource:options:fromPattern:player:error:].cold.1 + 104
2
CoreHaptics
+[CHHapticEngine(CHHapticEngineInternal) doRegisterAudioResource:options:fromPattern:player:error:] + 3784
3
CoreHaptics
-[CHHapticPattern resolveExternalResources:error:] + 388
4
CoreHaptics
-[PatternPlayer initWithPlayable:engine:privileged:error:] + 560
5
CoreHaptics
-[CHHapticEngine createPlayerWithPattern:error:] + 256
6
Mind
VoiceChatHapticEngine.swift - Line 170
VoiceChatHapticEngine.createThinkingHapticPlayer() + 170

Has anyone encountered similar crashes when working with CHHapticEngine and haptic patterns that contains audioCustom event?

Thank you so much for your help.

Ondrej

Hello @LookingForFont, thank you for posting a crash log. It doesn't look like the crash is related to your implementation, so please use Feedback Assistant to submit a bug report, and post here your bug report's ID. If you are able to replicate the crash, the please capture a sysdiagnose and attach it to your bug report, along with the exact time you were able reproduce the issue.

Hello @LookingForFont, you asked:

do you think there's a chance this could be connected to threading (Main/Background) issue? Or maybe.. is it better to manually register audio resources and create patterns manually instead of AHAP files?

It's difficult to say whether the issue is concurrency-related without more information. I do understand some crashes are difficult to reproduce.

Although not necessarily better than using AHAP, it might be a good idea to try registering an audio resource and initializing a CHHapticEvent from it to see if the issue persists.

Creating CHHapticPatternPlayer with AudioCustom Event crashes
 
 
Q