pixlwave / Waveform

An interactive audio waveform made with SwiftUI.
MIT License
76 stars 12 forks source link

Fatal error: Index out of range on setting the `selectedSamples` #14

Open heyaibek opened 10 months ago

heyaibek commented 10 months ago

Hey 👋🏻 I'm getting Fatal error: Index out of range exception on setting the selectedSamples range like so:

Waveform(
  generator: generator,
  selectedSamples: $selectedSamples,
  selectionEnabled: .constant(true)
)
.foregroundColor(.white)
.onAppear {
  selectedSamples = 0 ..< Int(generator.audioBuffer.frameLength)
}

What could be the issue?

pixlwave commented 8 months ago

Hey @heyaibek, did you manage to figure this one out?

heyaibek commented 8 months ago

Hey @pixlwave 👋🏻 I've noticed that the crash happens when selection is enabled by constant value like selectionEnabled: .constant(true). In your demo project, however, it depends on the toggle value to enable/disable the selection. So, I just put the same mechanism in my code. But I'm afraid that this bug should be fixed 😛