Author Topic: Plugin hangs the process. Help.  (Read 2828 times)

Lex

  • Guest
Plugin hangs the process. Help.
« on: July 16, 2011, 02:00:02 am »
Alright, I am currently, creating a plugin that adds a new menu to the menu bar, I've just encountered a couple of problems, one solved on my own, one i could need some assistance with.

First off, i had a problem with Code::blocks crashing every time i tried to update or uninstall my plugin, and when i for once shutdown Code::Blocks properly without crashing, the process kept hanging the the task manager. Got it analyzed down to being the MenuBar's Insert/Append/Perpend functions that triggered it on release/destructor/stuff. After searching around, i got the crash fixed so;

From
Code: [Select]
class UML__Blocks : public cbPlugin
{
public:
    *Inherited methods and such*

    wxMenu UMLMenu; //New Menu
protected:
    *More Inherited methods and such*
};



UML__Blocks::UML__Blocks() : new UMLMenu(wxT("UML Menu"))
{
    *derp*
}

void UML__Blocks::BuildMenu(wxMenuBar* MenuBar)
{
    MenuBar->Insert(3, &UMLMenu, wxT("UML"));

}
To
Code: [Select]
class UML__Blocks : public cbPlugin
{
public:
    *Inherited methods and such*

    wxMenu* UMLMenu; //New Menu
protected:
    *More Inherited methods and such*
};



void UML__Blocks::BuildMenu(wxMenuBar* MenuBar)
{
    UMLMenu = new wxMenu(wxT("UML"));
    MenuBar->Insert(3, UMLMenu, wxT("UML"));

}

That apparently threw the whole menu on the heap with help from a pointer. It fixed the crashing issue, but the other problem still persists.
The Process still hangs, on a normal shutdown, and i have pretty much no clue why, other than all the trouble began when i wanted to add the menu.
Can anyone please help, or at least guide me in the right direction? I'm sorry if it's because of a certain lack of c++ skills or if the answer was right in front of me the entire time,


-Lex

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Plugin hangs the process. Help.
« Reply #1 on: July 16, 2011, 04:26:08 pm »
The menu has to be created on the heap:

Quote from: http://docs.wxwidgets.org/stable/wx_wxmenu.html#wxmenu
Allocation strategy

All menus except the popup ones must be created on the heap. All menus attached to a menubar or to another menu will be deleted by their parent when it is deleted. As the frame menubar is deleted by the frame itself, it means that normally all menus used are deleted automatically.

I don't know why your plugin hangs.
But you can try to debug it. The needed settings depend very much on your system-configuration.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Plugin hangs the process. Help.
« Reply #2 on: July 16, 2011, 04:49:48 pm »
By the way, you do not need the UMLMenu member-variable and you should not free it yourself, because (as the wxWidgets docu says) it's owned by the parent-menu and you never need to do it yourself. Not even in OnRelease or similar functions, because all menus and toolbars will be recreated if a plugin is attached or released.