Weird behaviour of toggle button

hi guys, need help in fixing this,
i added few buttons to my audio plugin … one of them is behaving strangely,
it is not changing its togglestate when clicked and produces weird gui errors,
the errors are causing segmentation fault, the button when clicked should change its state to grey,
and set dynamic threshold, for all channels of all electrodes. strangely, button does not change its toggle state and throws segmentation fault,
when the button is on it should set dynamci threshold for channels and while off it must set default threshold for channels.

check pastebin for code and more description

Show the stack trace from the segmentation fault maybe?

Where’s the code for the button itself, it looks like you’ve written a custom one? Which button is it? An ElectrodeButton?

hi bazrush!!
it is a custom button , i am adding two more files, which may be useful
ElectrodeButtons.cpp and ElectrodeButtons.h

there is a class “ElectrodeEditorButton” which PUBLIC - ly inherits class "Button"
see ElectrodeButtons.h and ElectrodeButtons.cpp for the implementation.
class PLUGIN_API ElectrodeEditorButton : public Button line 64 ElectrodeButtons.h

in SpikeDetectorEditor.h line there is a declaration
Array<ElectrodeEditorButton*> electrodeEditorButtons;
there are 4 electrodeEditorButtons,
all these buttons are declared and implemented in SpikeDetectorEditor.cpp
like ElectrodeEditorButton* e4 = new ElectrodeEditorButton(“DTHR”, font);
first 3 work fine , i have problem in DTHR ,
i am pasting link to gdb stacktrace ,
i think you may also check this sister thread, it has two images and a pastebin telling more about this weird error.

the link of sister thread is

Okay, I’m guessing, because I’ve only got half the source to look at that the problem is with your UtilityButton object.

Usually when stuff crashes its’ an invalid pointer. So I’d suggest looking to see if that GenericButton pointer is valid, or if anything inside GenericButtons’ paint routine might be invalid, possibly it’s been deleted already, or the pointer was never set to a valid object?

However JUCE components remove themselves from their parents when you delete them, so that’s going to help narrow this down.

PS. You might want to use more ScopedPointer<> objects, remove the deleteAllChildren(). Apart from anything else you can guarantee that a ScopedPointer will be null when no object has been assigned to it - which may help debugging.