# Having an issue where after I close the program, I get the "this program closed unexpectedly" warning. Is there an easy way to debug this?

**URL:** <https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640>\
**Category:** General JUCE discussion\
**Created:** [April 2, 2019, 8:27pm UTC](https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640 "2019-04-02T20:27:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ComposerShield](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/composershield/32/6655_2.png) [@ComposerShield](https://forum.juce.com/u/ComposerShield)\
**Post date:** [April 2, 2019, 8:27pm UTC](https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640/1 "2019-04-02T20:27:42Z")

</div>

In the past, I’ve noticed this is caused by issues in a deconstructor but I honestly don’t know when the problem started or where to start looking.

---

<div class="post-metadata">

**Author:** ![holy-city](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@holy-city](https://forum.juce.com/u/holy-city)\
**Post date:** [April 2, 2019, 8:46pm UTC](https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640/2 "2019-04-02T20:46:45Z")

</div>

A lot of the time this happens because you’re leaking memory (or deleting something twice). Are you following RAII patterns, or are you being cavalier with allocation? (lots of calls to new/delete)

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [April 2, 2019, 8:59pm UTC](https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640/3 "2019-04-02T20:59:10Z")

</div>

Yes, just attach the debugger to the running process and call quit. So the debugger would show you, where exactly the problem occurred.

It is unlikely a leak, since those are usually silently ignored. The whole processes memory will be freed anyway (still bad practice to leak, and it should be resolved).

So it sounds more like stuff became dangling while unrolling the stack…

---

<div class="post-metadata">

**Author:** ![ComposerShield](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/composershield/32/6655_2.png) [@ComposerShield](https://forum.juce.com/u/ComposerShield)\
**Post date:** [April 3, 2019, 11:52am UTC](https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640/4 "2019-04-03T11:52:51Z")

</div>

Gotcha. I used the debugger in Xcode and closed the program. I traced it back from the line where it failed and saw that in my PluginEditor.cpp, it was complaining about my sliderAttachment unique pointers. I added .remove() on those unique pointers in the deconstructor and that fixed the problem. That seems odd to me though…because I don’t remember that being a problem before and I thought the point of smart pointers was that you don’t have to remember to delete them. Oh well, it’s fixed. Ha.

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [April 3, 2019, 11:56am UTC](https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640/5 "2019-04-03T11:56:29Z")

</div>

> [@ComposerShield](#):
>
> I thought the point of smart pointers was that you don’t have to remember to delete them.

Yes, they should work like that. Maybe it’s some kind of order of declaration issue that you got the crash?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [April 3, 2019, 12:25pm UTC](https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640/6 "2019-04-03T12:25:47Z")

</div>

That crash is a classic:  
Class members are constructed in the order of appearance in the class declaration and destroyed in the opposite order (what @Xenakios hinted in his post).

If you make sure to declare the Slider BEFORE the SliderAttachment you are safe from that crash, no code necessary. But I also like this suggestion from @yfede:

> [@Closing the Plug-In makes the DAW crash](https://forum.juce.com/t/closing-the-plug-in-makes-the-daw-crash/26700/11):
>
> Rather than adding a SliderAttachment member to each Slider, why don’t you keep around this kind of struct for whenever you need such a coupling: struct SliderWithAttachment { ScopedPointer \<Slider\> slider; ScopedPointer \<SliderAttachment\> attachment; }; This way, in your Editor you can simply add a member like: SliderWithAttachment knob; and voila, you have the knob.slider and the knob.attachment automatically deleted in the correct order, and also nicely bound together making the c…

---

<div class="post-metadata">

**Author:** ![ComposerShield](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/composershield/32/6655_2.png) [@ComposerShield](https://forum.juce.com/u/ComposerShield)\
**Post date:** [April 3, 2019, 1:35pm UTC](https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640/7 "2019-04-03T13:35:56Z")

</div>

Oh wow. That method looks great. I’ll give it a shot when I get the chance, thanks.

---

<div class="post-metadata">

**Author:** ![ComposerShield](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/composershield/32/6655_2.png) [@ComposerShield](https://forum.juce.com/u/ComposerShield)\
**Post date:** [April 3, 2019, 3:06pm UTC](https://forum.juce.com/t/having-an-issue-where-after-i-close-the-program-i-get-the-this-program-closed-unexpectedly-warning-is-there-an-easy-way-to-debug-this/32640/8 "2019-04-03T15:06:50Z")

</div>

Yep, that was it, haha. I changed the order that they were declared and I no longer needed to do the .remove()
