Resized() before constructor?



I´m relatively new to C++ and JUCE development. So don´t hammer on me :-)

I´m trying to get it right and as I thought it would be relatively simple to add a TextButton as a Pointer. Doing it as in the Tutorial works as expected, although in a previous project I managed to use ScopedPointers for Buttons/Sliders, etc.

having a ScopedPointer (or unique_ptr) always throws me an exception (using PluginHost) that when ->setBounds(x,y,w,h) is called, because the Object not yet exists.

In the Header I got:

    ScopedPointer<TextButton> bt_scope;

the Constructor:

    // Button Scope
    addAndMakeVisible(bt_scope = new TextButton("Scope Test"));

And then in the resized() Funktion:

    bt_scope->setBounds(10, 40, 30, 30);

It worked befor using JUCE 3.0.8. What am I missing here?

moving the setBounds from resized() to the Constructor works. But that is not how it is supposed to work right?


Sorry for that basic question. New guy working into PluginCoding :-)




Where/when are you setting the size of the parent?



first thing in the Constructor of the PluginEditor (which is the parent)


If you set a breakpoint at bt_scope->setBounds you can see where it's called ​from and whether it gets called before the button is created, which seems to be the case.


Well that would explain it then.



Thanks you guys...

I wasn´t aware that setSize calls the resized() function right away. I thought it would be a one time function for initialisation. But... actually... it makes sense... 

Thank you for pointing that out...