# Add delete tracks question

**URL:** <https://forum.juce.com/t/add-delete-tracks-question/68948>\
**Category:** Tracktion Engine\
**Created:** [June 7, 2026, 9:40pm UTC](https://forum.juce.com/t/add-delete-tracks-question/68948 "2026-06-07T21:40:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RLhelms](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@RLhelms](https://forum.juce.com/u/RLhelms)\
**Post date:** [June 7, 2026, 9:40pm UTC](https://forum.juce.com/t/add-delete-tracks-question/68948/1 "2026-06-07T21:40:42Z")

</div>

“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?”

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [June 9, 2026, 11:05am UTC](https://forum.juce.com/t/add-delete-tracks-question/68948/2 "2026-06-09T11:05:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RLhelms](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@RLhelms](https://forum.juce.com/u/RLhelms)\
**Post date:** [June 9, 2026, 5:38pm UTC](https://forum.juce.com/t/add-delete-tracks-question/68948/3 "2026-06-09T17:38:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RLhelms](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@RLhelms](https://forum.juce.com/u/RLhelms)\
**Post date:** [June 10, 2026, 1:32am UTC](https://forum.juce.com/t/add-delete-tracks-question/68948/4 "2026-06-10T01:32:12Z")

</div>

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. 😔 If you think of anything let me know i would appreciate it greatly.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [June 10, 2026, 10:24am UTC](https://forum.juce.com/t/add-delete-tracks-question/68948/5 "2026-06-10T10:24:24Z")

</div>

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.
