Kirix Support Forums

wxAUI Errors and Memory Leaks

Please post all general questions, comments, bug reports, and any other wxAUI feedback here.

wxAUI Errors and Memory Leaks

Postby T-Rex on Wed Nov 22, 2006 7:41 pm

Hello.

I'm trying to use wxAuiNotebook but it produces an error if I press on its tab.
Also I can see memory leaks when adding tabs to wxAuiNotebook.
Detected memory leaks!
Dumping objects ->
{5908} normal block at 0x00FEC888, 24 bytes long.
Data: <0 > 30 D1 15 00 FF FF FF FF 00 00 00 00 00 00 00 00
{5907} normal block at 0x01006F30, 364 bytes long.
Data: <T > 54 DD 98 00 00 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
The program '[3444] DockingWindowsSample.exe: Native' has exited with code 0 (0x0).


All this problems appear only in Debug mode.

The source coe is listed below.

Header
Code: Select all
#ifndef _DOCKING_WINDOWS_SAMPLE_MAINFRAME_H
#define _DOCKING_WINDOWS_SAMPLE_MAINFRAME_H

#include <wx/wx.h>
#include <wx/treectrl.h>
#include <wx/aui/aui.h>

#define wxDWSTitleStr _("Docking Windows Sample")

class DockingWindowsSampleMainFrame : public wxFrame
{
   wxAuiManager m_Manager;
   wxToolBar * m_StdToolBar;
   wxToolBar * m_AddToolBar;
   wxTreeCtrl * m_InfoTree;
   wxAuiNotebook * m_Notebook;   

   wxPanel * m_Page1;
   wxPanel * m_Page2;
   void CreateControls();
   void CreateStdToolBar();
   void CreateAddToolBar();
   void CreateInfoTree();
   DECLARE_DYNAMIC_CLASS(DockingWindowsSampleMainFrame)
public:
   DockingWindowsSampleMainFrame();
   DockingWindowsSampleMainFrame(wxWindow * parent,
            wxWindowID id = wxID_ANY,
            const wxString & title = wxDWSTitleStr,
            const wxPoint & pos = wxDefaultPosition,
            const wxSize & size = wxSize(650, 450),
            long style = wxDEFAULT_FRAME_STYLE);
   ~DockingWindowsSampleMainFrame();

   bool Create(wxWindow * parent,
            wxWindowID id = wxID_ANY,
            const wxString & title = wxDWSTitleStr,
            const wxPoint & pos = wxDefaultPosition,
            const wxSize & size = wxSize(650, 450),
            long style = wxDEFAULT_FRAME_STYLE);

   DECLARE_EVENT_TABLE()
   void OnExit(wxCommandEvent & event);

};

#endif


Implementation
Code: Select all
#include "DockingWindowsSampleMainFrame.h"
//#include "wxAuiAeroDockArt.h"

#include "wxwin16x16.xpm"
#include "new.xpm"
#include "fileopen.xpm"
#include "filesave.xpm"
#include "htmfoldr.xpm"

#include "cut.xpm"
#include "copy.xpm"
#include "find.xpm"

IMPLEMENT_DYNAMIC_CLASS(DockingWindowsSampleMainFrame, wxFrame);

enum
{
   ID_TOGGLE_STANDARD_TOOLBAR = 10001,
   ID_TOGGLE_ADDITIONAL_TOOLBAR,
   ID_TOGGLE_STATUSBAR,
   ID_LOAD_LAYOUT,
   ID_SAVE_LAYOUT,
   ID_NOTEBOOK,
   ID_INFO_TREE
};

BEGIN_EVENT_TABLE(DockingWindowsSampleMainFrame, wxFrame)
EVT_MENU(wxID_EXIT, DockingWindowsSampleMainFrame::OnExit)
END_EVENT_TABLE()

DockingWindowsSampleMainFrame::DockingWindowsSampleMainFrame()
{
}

DockingWindowsSampleMainFrame::DockingWindowsSampleMainFrame(wxWindow * parent,
   wxWindowID id, const wxString & title, const wxPoint & pos,
            const wxSize & size, long style)
{
   m_StdToolBar = NULL;
   m_AddToolBar = NULL;
   m_Page1 = NULL;
   m_Page2 = NULL;
   m_Notebook = NULL;
   Create(parent, id, title, pos, size, style);
}

DockingWindowsSampleMainFrame::~DockingWindowsSampleMainFrame()
{   
   m_Manager.UnInit();
}

bool DockingWindowsSampleMainFrame::Create(wxWindow * parent,
   wxWindowID id, const wxString & title, const wxPoint & pos,
   const wxSize & size, long style)
{
   bool res = wxFrame::Create(parent, id, title, pos, size, style);
   if(res)
   {
      SetIcon(wxIcon(wxwin16x16_xpm));
      CreateControls();
   }
   return res;
}

void DockingWindowsSampleMainFrame::CreateControls()
{
   wxMenuBar * menuBar = new wxMenuBar;
   SetMenuBar(menuBar);   

   wxMenu * fileMenu = new wxMenu;
   fileMenu->Append(wxID_NEW, _("New\tCtrl+N"));
   fileMenu->Append(wxID_OPEN, _("Open\tCtrl+O"));
   fileMenu->Append(wxID_SAVE, _("Save\tCtrl+S"));
   fileMenu->AppendSeparator();
   fileMenu->Append(wxID_EXIT, _("Exit\tAlt+F4"));

   wxMenu * toolbarsMenu = new wxMenu;
   toolbarsMenu->Append(ID_TOGGLE_STANDARD_TOOLBAR, _("Standard"));
   toolbarsMenu->Append(ID_TOGGLE_ADDITIONAL_TOOLBAR, _("Additional"));

   wxMenu * layoutMenu = new wxMenu;
   layoutMenu->Append(ID_LOAD_LAYOUT, _("Load"));
   layoutMenu->Append(ID_SAVE_LAYOUT, _("Save"));

   wxMenu * viewMenu = new wxMenu;
   viewMenu->Append(wxID_ANY, _("Toolbars"), toolbarsMenu);
   viewMenu->Append(wxID_ANY, _("Layout"), layoutMenu);
   viewMenu->Append(ID_TOGGLE_STATUSBAR, _("Status Bar"));   
   

   wxMenu * helpMenu = new wxMenu;
   helpMenu->Append(wxID_ABOUT, _("About..."));

   menuBar->Append(fileMenu, _("File"));
   menuBar->Append(viewMenu, _("View"));
   menuBar->Append(helpMenu, _("Help"));
   
   m_Manager.SetManagedWindow(this);

   /*wxAuiAeroDockArt * dockart = new wxAuiAeroDockArt;
   m_Manager.SetArtProvider(dockart);*/

   CreateStatusBar();
   CreateStdToolBar();
   CreateAddToolBar();
   CreateInfoTree();
   
   m_Notebook = new wxAuiNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxSize(600, 450));
   m_Page1 = new wxPanel(m_Notebook, wxID_ANY);
   m_Page2 = new wxPanel(m_Notebook, wxID_ANY);
   m_Notebook->AddPage(m_Page1, _("Page1"));
   m_Notebook->AddPage(m_Page2, _("Page2"));

   m_Manager.AddPane(m_Notebook, wxAuiPaneInfo().CenterPane());
   m_Manager.AddPane(m_StdToolBar, wxAuiPaneInfo().ToolbarPane().Top());
   m_Manager.AddPane(m_AddToolBar, wxAuiPaneInfo().ToolbarPane().Top().Position(2));
   m_Manager.AddPane(m_InfoTree, wxAuiPaneInfo().Left());

   m_Manager.Update();
}

void DockingWindowsSampleMainFrame::CreateStdToolBar()
{   
   m_StdToolBar = new wxToolBar(this, wxID_ANY, wxDefaultPosition,
      wxDefaultSize, wxBORDER_NONE|wxTB_HORIZONTAL|wxTB_NODIVIDER|wxTB_FLAT);
   /*wxAuiAeroDockArt * dockart = (wxAuiAeroDockArt *) m_Manager.GetArtProvider();
   if(dockart)
   {
      m_StdToolBar->SetBackgroundColour(dockart->GetBackgroundBrush().GetColour());
   }*/
   m_StdToolBar->SetToolBitmapSize(wxSize(16, 15));
   m_StdToolBar->AddTool(wxID_NEW, _("New"), wxBitmap(new_xpm));
   m_StdToolBar->AddTool(wxID_OPEN, _("Open"), wxBitmap(fileopen_xpm));
   m_StdToolBar->AddTool(wxID_SAVE, _("Save"), wxBitmap(filesave_xpm));
   m_StdToolBar->AddSeparator();
   m_StdToolBar->AddTool(wxID_ABOUT, _("About..."), wxBitmap(htmfoldr_xpm));
   m_StdToolBar->Realize();
}

void DockingWindowsSampleMainFrame::CreateAddToolBar()
{
   m_AddToolBar = new wxToolBar(this, wxID_ANY, wxDefaultPosition,
      wxDefaultSize, wxBORDER_NONE|wxTB_HORIZONTAL|wxTB_NODIVIDER|wxTB_FLAT);
   /*wxAuiAeroDockArt * dockart = (wxAuiAeroDockArt *) m_Manager.GetArtProvider();
   if(dockart)
   {
      m_AddToolBar->SetBackgroundColour(dockart->GetBackgroundBrush().GetColour());
   }*/
   m_AddToolBar->SetToolBitmapSize(wxSize(16, 15));
   m_AddToolBar->AddTool(wxID_CUT, _("Cut"), wxBitmap(cut_xpm));
   m_AddToolBar->AddTool(wxID_COPY, _("Copy"), wxBitmap(copy_xpm));
   m_AddToolBar->AddTool(wxID_FIND, _("Find"), wxBitmap(find_xpm));
   m_AddToolBar->Realize();
}

void DockingWindowsSampleMainFrame::CreateInfoTree()
{
   m_InfoTree = new wxTreeCtrl(this, ID_INFO_TREE, wxDefaultPosition, wxSize(170, 250),
      wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxTR_SINGLE);
   wxTreeItemId root = m_InfoTree->AddRoot(_("Document"));
   m_InfoTree->AppendItem(root, _("Item 1"));
   m_InfoTree->AppendItem(root, _("Item 2"));
   m_InfoTree->AppendItem(root, _("Item 3"));
   m_InfoTree->Expand(root);
}

void DockingWindowsSampleMainFrame::OnExit(wxCommandEvent & event)
{
   Close();
}



Does anybody know how to solve this problem?

wxWidgets-2.7.2
wxWidgets-2.8.0-rc1
VS2005
T-Rex
Registered User
 
Posts: 10
Joined: Sun Dec 25, 2005 6:57 am
Location: Ukraine

Postby Ben on Thu Nov 23, 2006 2:12 am

Hi,

Thanks. You found a bad bug in wxAuiNotebook. Thankfully, I've been able to fix it. Basically, wxAuiNotebook was eating its own event which caused an assert failure.

I've fixed the bug in wxWidgets CVS head.

Here's the patch if you'd like to just patch your rc1. I would, however, recommend that you try out the CVS head version, because we have been fixing many other bugs since then (and also finished various renaming work).

Also, can you post a screenshot of your custom dock art class? I'd love to see what you've done!

Best,
Ben

Code: Select all
--- auibook.cpp 2006/11/21 16:37:36     1.82
+++ auibook.cpp 2006/11/23 07:07:37
@@ -2806,14 +2806,14 @@
     evt.SetSelection(new_page);
     evt.SetOldSelection(m_curpage);
     evt.SetEventObject(this);
-    if (!GetEventHandler()->ProcessEvent(evt) || evt.IsAllowed())
+    if (!GetParent()->GetEventHandler()->ProcessEvent(evt) || evt.IsAllowed())
     {
         int old_curpage = m_curpage;
         m_curpage = new_page;

         // program allows the page change
         evt.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED);
-        (void)GetEventHandler()->ProcessEvent(evt);
+        (void)GetParent()->GetEventHandler()->ProcessEvent(evt);


         wxAuiTabCtrl* ctrl;
@@ -3437,7 +3437,7 @@
             e.SetSelection(m_tabs.GetIdxFromWindow(close_wnd));
             e.SetOldSelection(evt.GetSelection());
             e.SetEventObject(this);
-            GetEventHandler()->ProcessEvent(e);
+            GetParent()->GetEventHandler()->ProcessEvent(e);
             if (!e.IsAllowed())
                 return;
User avatar
Ben
Kirix Support Team
 
Posts: 525
Joined: Mon Dec 19, 2005 6:29 am

Postby T-Rex on Thu Nov 23, 2006 6:34 am

Hello.

Thanks for patch. :) I'll try it today.

---
This dockart class is still work in progress. Its source code will be available as a part of article about docking windows at http://wxwidgets.info
I'm planning to finish it in nearest future but there is still a lot fo work with wxAuiTabArt class which will provide the same look for wxAuiNotebook.

Regards,
T-Rex
T-Rex
Registered User
 
Posts: 10
Joined: Sun Dec 25, 2005 6:57 am
Location: Ukraine

Postby T-Rex on Thu Nov 23, 2006 12:04 pm

Also one more thing.

Code: Select all
wxAuiAeroDockArt * dockart = new wxAuiAeroDockArt;
   m_Manager.SetArtProvider(dockart);

   CreateStatusBar();
   CreateStdToolBar();
   CreateAddToolBar();
   CreateInfoTree();
   
   m_Notebook = new wxAuiNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxSize(600, 450),
      wxAUI_NB_DEFAULT_STYLE|wxNO_BORDER);
   m_Page1 = new wxPanel(m_Notebook, wxID_ANY);
   m_Page2 = new wxPanel(m_Notebook, wxID_ANY);
   m_Notebook->AddPage(m_Page1, _("Page1"));
   m_Notebook->AddPage(m_Page2, _("Page2"));

   m_Manager.AddPane(m_Notebook, wxAuiPaneInfo().CenterPane());
   m_Manager.AddPane(m_StdToolBar, wxAuiPaneInfo().ToolbarPane().Top().Floatable(false));
   m_Manager.AddPane(m_AddToolBar, wxAuiPaneInfo().ToolbarPane().Left().Layer(2).
      GripperTop().Floatable(false));
   m_Manager.AddPane(m_InfoTree, wxAuiPaneInfo().Left().Layer(1).PinButton().
      MinimizeButton().MaximizeButton().Caption(wxT("Information")));

   m_Manager.Update();


If you press Maximize button and then press Pin button on maximized "Information" pane then center pane does not appear and frame manager does not update empty area
[url=http://wxwidgets.info]wxwidgets.info - Articles and Tutorials
wxToolBox - wxWidgets components that works like VisualStudio ToolBox
T-Rex
Registered User
 
Posts: 10
Joined: Sun Dec 25, 2005 6:57 am
Location: Ukraine

Postby azheng0305 on Wed Dec 20, 2006 12:24 am

Detected memory leaks!
Dumping objects ->
{5908} normal block at 0x00FEC888, 24 bytes long.
Data: <0 > 30 D1 15 00 FF FF FF FF 00 00 00 00 00 00 00 00
{5907} normal block at 0x01006F30, 364 bytes long.
Data: <T > 54 DD 98 00 00 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.

I have the same problem, but i am using 'wxWidgets 2.8.0 stable release',so,is the bug existing even now?

wxWidgets 2.8.0 stable
ms vc7.1
windows xp
azheng0305
Registered User
 
Posts: 2
Joined: Wed Dec 20, 2006 12:14 am

Postby Ben on Thu Dec 21, 2006 12:48 am

Hi,

Yes, there are probably a few small memory leaks left-- nothing really serious though. I'll see if I can close them up.

Thanks,
Ben
User avatar
Ben
Kirix Support Team
 
Posts: 525
Joined: Mon Dec 19, 2005 6:29 am

Postby corsix on Mon Jan 01, 2007 6:41 am

After getting the same leak from wxWidgets version 2.8.0 stable/release, looking through the auibook.cpp source, the patch from ben listed above had not been applied. Unofrtunatly, after applying the patch and recompiling wxAui, I still have the leak. Could there be other patches that did not make 0.8.0, and if so, is there a place to download the updated source code? (http://www.kirix.com/community/wxaui/downloads.html does not list 0.9.3 because "it is included in 2.8.0").
corsix
Registered User
 
Posts: 1
Joined: Mon Jan 01, 2007 6:35 am

Postby Ben on Mon Jan 01, 2007 2:09 pm

Hi there,

I didn't get a chance to fix these memory leaks yet. In the flurry of the release, I spent my time working on other arguably more serious problems. I'm sorry I didn't get around to it. I'll try again for wxWidgets 2.8.1.

Thanks,
Ben
User avatar
Ben
Kirix Support Team
 
Posts: 525
Joined: Mon Dec 19, 2005 6:29 am

Postby azheng0305 on Sat Jan 06, 2007 7:58 pm

Seems problem is

Code: Select all
wxAuiTabCtrl* wxAuiNotebook::GetActiveTabCtrl():
{
    //...
    wxTabFrame* tabframe = new wxTabFrame; //at line 2929 on auibook.cpp
   //...
}



Class wxTabFrame has no parent window parameter in its constructor...

======

But when i try to patch this and set this( it is wxAuiNotebook ) or m_mgr.GetManageredWindow() as its parent, memory leaks are gone, but the left scroll button doesn't work any more.
azheng0305
Registered User
 
Posts: 2
Joined: Wed Dec 20, 2006 12:14 am

Postby Ben on Sun Jan 07, 2007 9:00 am

Hi,

Thanks. Creating the wxTabFrame object without a window is, however, intentional. wxTabFrame is a window-less 'container' whose only purpose is being a sizer item to find out where the tab control should be positioned.

It looks like simply deleting the object will fix this leak.

Thanks for the report.

Ben
User avatar
Ben
Kirix Support Team
 
Posts: 525
Joined: Mon Dec 19, 2005 6:29 am

Postby sickboy on Wed Jun 20, 2007 6:58 am

This bug still exist in wxMSW2.8.4
Anyone has a fix ?
sickboy
Registered User
 
Posts: 7
Joined: Wed Jun 06, 2007 8:40 am

Return to wxAUI Questions, Thoughts & Feedback