Dear All
I'm getting confused with scopedpointer. I have the following code:
MainContent.h
class MainContent : public Component
{
public:
//==============================================================================
MainContent ();
~MainContent();
//==============================================================================
//[UserMethods] -- You can add your own custom methods in this section.
void enableDisableUIFromConnectedDevice();
//[/UserMethods]
void paint (Graphics& g);
void resized();
private:
//[UserVariables] -- You can add your own custom variables in this section.
//[/UserVariables]
//==============================================================================
ScopedPointer<TabbedComponent> tabbedComponent;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContent)
};
As shown above, tabbedComponent was declared as a scopedpointer by introjucer.
I'm trying to get the content of the tab at index 0 from one of my functions which is declared in the scope.
MainContent.cpp
#include "MainContent.h"
#include "MidiController.h"
//[MiscUserDefs] You can add your own user definitions and misc code here...
//[/MiscUserDefs]
//==============================================================================
MainContent::MainContent ()
: Component ("mainContent")
{
addAndMakeVisible (tabbedComponent = new TabbedComponent (TabbedButtonBar::TabsAtTop));
tabbedComponent->setTabBarDepth (29);
tabbedComponent->addTab ("Xkey", Colours::lightgrey, new XkeyClass(), true);
tabbedComponent->addTab ("Velocity Curves", Colours::lightgrey, new VelocityCurvesClass(), true);
tabbedComponent->addTab ("Sensitivity & Gain", Colours::lightgrey, new SensitivityClass(), true);
tabbedComponent->setCurrentTabIndex (0);
//[UserPreSize]
//[/UserPreSize]
setSize (800, 600);
//[Constructor] You can add your own custom stuff here..
MidiController *midiController = MidiController::getInstance();
midiController->initMidiController();
//[/Constructor]
}
MainContent::~MainContent()
{
MidiController::deleteInstance();
tabbedComponent = nullptr;
}
void MainContent::enableDisableUIFromConnectedDevice()
{
// Grab a ref to MIDIcontroller
MidiController *midiController = MidiController::getInstance();
// get a ref to the first tab content -> PROBLEM
Component* comp = tabbedComponent->getTabContentComponent(TAB_MYXEY);
...
}
The problem is above, tabbedComponent is no longer set (it is 0x000000) when entering into this function, which is in the scope.
So the getTabContentComponent crashes my app.
I do not understand why the tabbedComponent scopedpointer is lost here since my function is declared in the scope ?
What am I missing ?
Thanks for any help or tip.
J
