Closed orchetect closed 3 years ago
Thanks for the information in any case! I wasn’t aware of @_optimize
.
The issue is brutally elusive so I'm taking a hint from your implementation to see if a C-based MIDIPacketNext wrapper and unsafe memory access can prevent crashes in some of my own code.
This has been a long-standing issue with CoreMIDI in Swift and I really wish Apple would care enough to fix it.
I've seen many other libraries dogged with this same issue because it doesn't always crop up right away.
@orchetect Hey! Do you still experience the MIDIPacketNext.pointee
crash?
It seems I managed to solve this by iterating midi packet lists with:
for packet in packetList.unsafeSequence() {
for event in packet.pointee {
// ...
}
}
Yes unsafeSequence()
works well to iterate packets but it's only available on more recent Apple platforms - macOS 10.15, iOS 13.0, macCatalyst 13.0.
What I found was different memory issues and crashes would appear depending on the OS version, so I had to add some robustness to handling the pointers on older platforms. If you're curious I can link some of the solutions. But If you're comfortable dropping support for older platforms then just go with the new API.
Depending on what's happening in the custom event iterator to process each packet, there may still be residual issues.
for event in packet.pointee // invoking custom iterator
Disregard - issue persists and remains elusive after further testing.