It seems to not be initialised, even though it passes the isValid() function - getNumChildren() returns a large random value (e.g. 27888).
I've just rearranged some code and it looks like the InterfaceComponent constructor is called before the MainContentComponent one, so that the object I am trying to share has not been initialised when the nested Component is trying to access it. I would expect the ValueTree to not be valid in this case.
Perhaps I am going about this a strange way, basically just want a way of sharing data across components.
InterfaceComponent also inherits Value::Listener, to update a GUI element with incoming values.
For a reason I cannot work out, the InterfaceComponent::valueChanged override function says the valueTree is nullptr, even though the log output says it has been previously initialised by the setValueTree function (which shows correct output).
They have value semantics, and although you might sometimes want to pass them by reference, there's almost never a good reason to take a pointer to one.
Ok, thanks, I did try without and was getting similar behaviour, i.e. the ValueTree having random values when called from the valueChanged function... I'll take out the pointer and report back.
OK - I have now taken out the pointer to the ValueTree, but the problem remains - the valueChanged function gets an invalid (empty) ValueTree where it has been set and tested to be valid in the setValueTree function, which is called before the valueChanged function as I can see in the log output..
Sorry guys, I oversimplified the code I posted, and actually the problem was a nullptr to the InterfaceComponent, as it is nested inside a TabbedComponent, and I wasn't checking for nullptr before calling the method - I changed static_cast to dynamic and followed how its done in Introjucer, using jassert to make sure, and then discovered the getTabContentComponent function which was what I needed to get at the necessary component.
Hope I have not cluttered the forum with my debugging, Jules feel free to delete thread in case it confuses people searching in future...