# PluginEditor construction happens twice

**URL:** <https://forum.juce.com/t/plugineditor-construction-happens-twice/19598>\
**Category:** Audio Plugins\
**Created:** [October 23, 2016, 6:09pm UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598 "2016-10-23T18:09:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![SubRivers](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@SubRivers](https://forum.juce.com/u/SubRivers)\
**Post date:** [October 23, 2016, 6:09pm UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/1 "2016-10-23T18:09:53Z")

</div>

Hi,

I noticed that this first in a plugin I am working on but I took a look at the JuceDemoPlugin and the PluginEditor construction is also being carried out twice.

Wondering if this is a bug in JUCE or perhaps with the demo ?

---

<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:** [October 23, 2016, 6:14pm UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/2 "2016-10-23T18:14:25Z")

</div>

Does it happen because of what the host using the plugin does? In any case, you should be prepared for things like that to happen. Just be careful to not leak any memory when the plugin GUI is created and destroyed multiple times.

---

<div class="post-metadata">

**Author:** ![SubRivers](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@SubRivers](https://forum.juce.com/u/SubRivers)\
**Post date:** [October 23, 2016, 6:55pm UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/3 "2016-10-23T18:55:57Z")

</div>

I have been testing it within Cubase 8

I’ve checked it with another host (MuLab) which I use for quick debugging and it constructs twice there as well.

It isn’t really causing any serious issue for me it just seemed to be an anomaly.

I found it while debugging.

---

<div class="post-metadata">

**Author:** ![chrisboy2000](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@chrisboy2000](https://forum.juce.com/u/chrisboy2000)\
**Post date:** [October 23, 2016, 9:30pm UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/4 "2016-10-23T21:30:25Z")

</div>

Some hosts create it twice to get the window size.

---

<div class="post-metadata">

**Author:** ![SubRivers](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@SubRivers](https://forum.juce.com/u/SubRivers)\
**Post date:** [October 23, 2016, 11:02pm UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/5 "2016-10-23T23:02:17Z")

</div>

Yes - I can see why hosts might construct a plugin twice -lets them have a sneaky peek first.

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [October 27, 2016, 9:49am UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/6 "2016-10-27T09:49:37Z")

</div>

Yes many hosts create the plug-in editor twice.

---

<div class="post-metadata">

**Author:** ![joe-04-04](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/joe-04-04/32/2566_2.png) [@joe-04-04](https://forum.juce.com/u/joe-04-04)\
**Post date:** [June 28, 2017, 4:48am UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/7 "2017-06-28T04:48:34Z")

</div>

Don’t mean to resurrect an old thread, but I’ve noticed this issue a few times and was always curious as to why it happened. The issue it caused for me was, when displaying a nag screen in the constructor of the pluginEditor, the user would have to dismiss it twice, as the constructor is called twice. Any good work arounds for this? I want it to be a nag screen to purchase, but I don’t want them to have to click twice.

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [June 28, 2017, 8:48am UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/8 "2017-06-28T08:48:22Z")

</div>

Sorry, there is nothing that we can do about this. If the hosts asks the plug-in to open it’s editor twice in a row, well then there is nothing we can do about that.

---

<div class="post-metadata">

**Author:** ![andrewj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/andrewj/32/13428_2.png) [@andrewj](https://forum.juce.com/u/andrewj)\
**Post date:** [June 28, 2017, 8:51am UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/9 "2017-06-28T08:51:45Z")

</div>

Perhaps try only showing the nag only after a short timer so it doesn’t pop up if the host is just doing a quick instantiation of the editor. Also use a member variable to record whether you’ve already displayed the nag so don’t show it again if user closes then opens the editor later on.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 28, 2017, 8:58am UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/10 "2017-06-28T08:58:47Z")

</div>

It’d be much better UX to show the nag screen as an overlay inside your editor rather than a separate box.

---

<div class="post-metadata">

**Author:** ![soundbytes1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/soundbytes1/32/2105_2.png) [@soundbytes1](https://forum.juce.com/u/soundbytes1)\
**Post date:** [June 28, 2017, 2:36pm UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/11 "2017-06-28T14:36:29Z")

</div>

> [@joe\_04\_04](#):
>
> I don’t want them to have to click twice.

You could trigger the nag screen in prepareToPlay(). (that’s what I do + my nagscreen is an overlay as jules suggested.)  
Only make sure not to block anything with the nag screen. That would be a bit too much nagging and might cause people to loose confidence in the quality of your products.

---

<div class="post-metadata">

**Author:** ![joe-04-04](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/joe-04-04/32/2566_2.png) [@joe-04-04](https://forum.juce.com/u/joe-04-04)\
**Post date:** [June 28, 2017, 3:23pm UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/12 "2017-06-28T15:23:20Z")

</div>

Sounds good! I’ll give this a try when I get back home! Thanks for the tip!

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [June 29, 2017, 8:14am UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/13 "2017-06-29T08:14:01Z")

</div>

> [@soundbytes1](#):
>
> You could trigger the nag screen in prepareToPlay()

This sounds as much arbitrary as the original solution if not a little worse: to my knowledge the `prepareToPlay()` may be called multiple times during plug-in initialization, AND the Editor at those times is not even guaranteed to be existing and showing.

---

<div class="post-metadata">

**Author:** ![SubRivers](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@SubRivers](https://forum.juce.com/u/SubRivers)\
**Post date:** [June 30, 2017, 10:18pm UTC](https://forum.juce.com/t/plugineditor-construction-happens-twice/19598/14 "2017-06-30T22:18:18Z")

</div>

I was the OP

I really only raised the subject to make sure I wasn’t missing something as it had no real affect on my dev at the time but just seemed an oddity.

But I can see the use in having places to hang singular events like a nag screen.

with audio plugins it isn’t a problem to handle it as time is part of the pact.

But for consistency it would probably be a good to have a hook for such things
