Add delete tracks question

“Using Tracktion Engine with JUCE 8. When I call edit.deleteTrack(trackPtr) from a button’s onClick lambda inside a component that’s owned by an OwnedArray that gets rebuilt in the edit’s ValueTree listener, the component gets destroyed mid-execution. What’s the correct pattern for deleting a track from a track header component?”

I think you’d usually use a juce::Component::BailOutChecker for this and just return if it gets nulled (shouldBailOut returns true) after the deleteTrack call.

Thanks dave96 i will give that a try and see what i get

Sadly, that did not solve the issue. What is happening is that when you add 3 or 4 tracks and you go to delete them track 3 will delete track 4, track 2 will delete track 3 and so forth. You can’t delete track 1. Sometimes add a track deletes a track. The other issue i have is that input routing kind of does the same thing, it seems to always default to tracks 1 and 2. I am at the point of the project opens hears audio, records to a track, scans for plugin mutes and solos, volume on the mixer channels work, and these pop up when tracks are added. now i am stalled out. :pensive_face: If you think of anything let me know i would appreciate it greatly.

Perhaps you could provide a stack trace of the crash?

I’m not quite sure what you mean by “track 3 deletes track 4”, if that’s the case, what is crashing as if the button to delete track 4 lives on track 3, pressing it shouldn’t delete track 3 should it?

There is one other way to do this which is to keep the Track alive in the UI Component by storing a Track::Ptr rather than a raw Track*. You will have to make sure you don’t keep on to this for a long time though as you’ll keep the track alive. What you’d usually do is in the owner of your track UI components, when the child related to the track is removed, you delete the child component. That should mean that the actual Track lifetime is extended just enough to survive that ValueTree callback loop.

I hope that makes sense.