Close Button Crash!


#1

Hello!

I have a problem: when I click on close button on the main window app crashes...

Xcode shows me a SIGABRT signal at menuBar destructor... Any suggestion?

 


#2

How about a "setMenuBar(nullptr);" in your destructor?


#3

Thanks Rory,

but I've tried with:

aud_MenuBar::~aud_MenuBar()

{

    deleteAllChildren();

    menuBar.MenuBarComponent::setModel(nullptr);

}

and the issue continues: 

malloc: *** error for object 0x10181d9f8: pointer being freed was not allocated

#4

Actually, setMenuBar() is a member of the DocumentWindow class.  I take it your menu bar is being used in some sort of resizable window?


#5

That's correct. It's being used in a resizable window


#6

That's correct. It's being used in a resizable window


#7

And you add it by calling "setMenuBar(this, height)" in the constructor. So in the destructor for that window call "setMenuBar(0)".  


#8

I fix the problem deleting this line in the destructor:

deleteAllChildren();

Thanks!


#9

I'm running into the same problem with the MidiKeyboardComponent class.   Every example I've seen for the MidiKeyboardComponent shows deleteAllChildren() being used in the destructor for the class that's holding the MidiKeyboardComponent.   There's also no indication if the class instance of MidiKeyboardComponent should be a pointer initialized via 'new' or explicitly initialized in the class constructor.    The first tutorial for JUCE (http://lubyk.org/en/software/mimas/document171.pdf) shows how to use components as pointer variables, and makes use of the deleteAllChildren() method.  

 

Are we supposed to follow this tutorial's demonstration for using ALL components offering in JUCE?

 

i.e. always use 

class SubComponent : public Component

{

public: 

  SubComponent();

  ~SubComponent();

  MidiKeyboardState* state;

  MidiKeyboardComponent* keyboard;

  void paint( Graphics&) override;

  void resized() override;

};

SubComponent::SubComponent()

{

  state = new MidiKeyboardState();

  keyboard = new MidiKeyboardComponent( &state, MidiKeyboardComponent::horizontalKeyboard);

  addAndMakeVisible( keyboard );

}

SubComponent::~SubComponent()

{

  deleteAllChildren();

}

 

and never use:

 ​
class SubComponent : public Component

{

  public: SubComponent();

  ~SubComponent();

  MidiKeyboardState state;

  MidiKeyboardComponent keyboard;

  void paint( Graphics&) override;

  void resized() override;

};

SubComponent::SubComponent()

: keyboard( state, MidiKeyboardComponent::horizontalKeyboard);

{ 

  addAndMakeVisible( keyboard );

}

SubComponent::~SubComponent()

{ 
  //deleteAllChildren(); 
}

#10

Please don't use deleteAllChildren()!

I don't use it in my own example code, but obviously I can't stop other people putting it in their tutorials. It's not a robust way to manage object lifetimes - much better to manage the component as a normal member variable, or use a ScopedPointer to it if you really need to create it on the heap.