I've come across a scenario in my project where I need to register a ChangeListener with a ChangeBroadcaster, but these two components are in entirely separate parts of the GUI. The new tutorial was a lot of help, but its listener and broadcaster exist within the same class definition.
My plugin is crashing when the asyncronous callback is triggered (EXC_BAD_ACCESS), and it occurs when the broadcaster dereferences the listener pointer that was registered with it. This leads me to believe that the pointer I'm registering is wrong in some way - unfortunately I don't know enough about C++ to know why...
The component tree looks like this:
Container ----- DetailsChangeListener
|
AudioProcessorEditor -----
|
SideBar -------- DetailsChangeBroadcaster
//*************************
// DetailsChangeListener
//*************************
...
void DetailsChangeListener::changeListenerCallback (ChangeBroadcaster *source)
{
dummyText.setText("meow", NotificationType::dontSendNotification);
}
//*************************
// DetailsChangeBroadcaster
//*************************
...
DetailsChangeBroadcaster::DetailsChangeBroadcaster() : selectedRow(-1)
{
// Here's the code that crashes the thread. See the implementation of getDetailsView below.
addChangeListener( ((EqipAudioProcessorEditor*)getTopLevelComponent())->getDetailsView() );
addAndMakeVisible(listBox);
listBox.setModel(this);
}
void PluginList::listBoxItemClicked(int row, const MouseEvent& e) {
selectedRow = row;
sendChangeMessage();
}
//*************************
// EqipAudioProcessorEditor
//*************************
DetailsChangeListener* EqipAudioProcessorEditor::getDetailsView() {
return container.getDetailsView();
}
//*************************
// Container
//*************************
DetailsChangeListener* Container::getDetailsView() {
return &detailsChangeListener;
}
Thanks in advance to anyone that can help!
