Resized() before constructor?


#1

Hi,

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:

private:
    ScopedPointer<TextButton> bt_scope;

the Constructor:

    // Button Scope
    addAndMakeVisible(bt_scope = new TextButton("Scope Test"));
    bt_scope->addListener(this);

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 :-)

cheers

hendrix


#2

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

Rail


#3

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


#4

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.


#5

Well that would explain it then.

Rail


#6

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...