On 2016-1-21 1:31, Vadim Zeitlin wrote:
> On Tue, 19 Jan 2016 21:07:04 +0800 asmwarrior wrote:
>
> a> Thanks for the reply. It looks like this issue is NOT related the XRC
> a> handler in C::B, because I can reproduce this issue by just running C++
> a> code inside the constructor of the dialog, such as:
>
> Thanks, this is useful to know as we can eliminate a lot of things from
> consideration now.
>
> But, just to be sure: if you use this code in e.g. the minimal sample it
> still doesn't show the problem? This seems completely incredible :-(
>
> VZ
>
Hi, VZ, thanks.
I just created a very simple wx minimal sample, and when I click on the menu item, I just open the wxDialog.
I use the C++ code to construct this dialog, so no XRC related code.
You have to add two member declaration inside the Header file, such as:
wxListbook *m_listbook1;
wxPanel *m_panel6;
I see that the application just crashed. It has such call stack
Program received signal SIGSEGV, Segmentation fault.
At F:\wx\wxWidgets_trunk\src\generic\listbkg.cpp:277
----------------------------------------------
[debug]> bt 30
[debug]#0 0x00829369 in wxListbook::SetImageList (this=0xe891338, imageList=0xe88c9b8) at F:\wx\wxWidgets_trunk\src\generic\listbkg.cpp:277
[debug]#1 0x004051a9 in wxWithImages::AssignImageList (this=0xe8914c4, imageList=0xe88c9b8) at F:\wx\wxWidgets_trunk\include\wx\withimages.h:50
[debug]#2 0x004017e2 in NewDialog::NewDialog (this=0x22f424, parent=0xe8d5d58) at D:\temp\test-listbook-load-xrc2\NewDialog.cpp:241
[debug]#3 0x00402840 in test_listbook_load_xrc2Frame::OnAbout (this=0xe8d5d58, event=...) at D:\temp\test-listbook-load-xrc2\test_listbook_load_xrc2Main.cpp:106
[debug]#4 0x005a387a in wxAppConsoleBase::HandleEvent (this=0xe83b898, handler=0xe8d5d58, func=(void (wxEvtHandler::*)(wxEvtHandler * const, wxEvent &)) 0x40281a <test_listbook_load_xrc2Frame::OnAbout(wxCommandEvent&)>, event=...) at F:\wx\wxWidgets_trunk\src\common\appbase.cpp:657
[debug]#5 0x005a38d6 in wxAppConsoleBase::CallEventHandler (this=0xe83b898, handler=0xe8d5d58, functor=..., event=...) at F:\wx\wxWidgets_trunk\src\common\appbase.cpp:669
[debug]#6 0x0066c4cf in wxEvtHandler::ProcessEventIfMatchesId (entry=..., handler=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1381
[debug]#7 0x0066b507 in wxEventHashTable::HandleEvent (this=0x41308c <test_listbook_load_xrc2Frame::sm_eventHashTable>, event=..., self=0xe8d5d58) at F:\wx\wxWidgets_trunk\src\common\event.cpp:989
[debug]#8 0x0066c93f in wxEvtHandler::TryHereOnly (this=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1578
[debug]#9 0x00cb6c04 in wxEvtHandler::TryBeforeAndHere (this=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\include\wx\event.h:3662
[debug]#10 0x0066c78b in wxEvtHandler::ProcessEventLocally (this=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1511
[debug]#11 0x0066c72c in wxEvtHandler::ProcessEvent (this=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1484
[debug]#12 0x0081084f in wxWindowBase::TryAfter (this=0xe889bf0, event=...) at F:\wx\wxWidgets_trunk\src\common\wincmn.cpp:3468
[debug]#13 0x0066c757 in wxEvtHandler::ProcessEvent (this=0xe889bf0, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1497
[debug]#14 0x0066c9cb in wxEvtHandler::SafelyProcessEvent (this=0xe889bf0, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1602
[debug]#15 0x0080b89c in wxWindowBase::HandleWindowEvent (this=0xe889bf0, event=...) at F:\wx\wxWidgets_trunk\src\common\wincmn.cpp:1542
[debug]#16 0x007d1419 in wxMenuBase::DoProcessEvent (menu=0xe890d88, event=..., win=0xe8d5d58) at F:\wx\wxWidgets_trunk\src\common\menucmn.cpp:676
[debug]#17 0x007d1362 in wxMenuBase::SendEvent (this=0xe890d88, itemid=101, checked=-1) at F:\wx\wxWidgets_trunk\src\common\menucmn.cpp:646
[debug]#18 0x00794851 in wxFrameBase::ProcessCommand (this=0xe8d5d58, item=0xe890e50) at F:\wx\wxWidgets_trunk\src\common\framecmn.cpp:294
[debug]#19 0x0070585e in wxFrame::HandleCommand (this=0xe8d5d58, id=101, cmd=0, control=0x0) at F:\wx\wxWidgets_trunk\src\msw\frame.cpp:799
[debug]#20 0x00705a58 in wxFrame::MSWWindowProc (this=0xe8d5d58, message=273, wParam=101, lParam=0) at F:\wx\wxWidgets_trunk\src\msw\frame.cpp:849
[debug]#21 0x006da75f in wxWndProc(HWND__*, unsigned int, unsigned int, long)@16 (hWnd=0x60178, message=273, wParam=101, lParam=0) at F:\wx\wxWidgets_trunk\src\msw\window.cpp:2649
[debug]#22 0x7e418734 in USER32!GetDC () from C:\WINDOWS\system32\user32.dll
[debug]#23 0x00060178 in ?? ()
[debug]#24 0x00000111 in ?? ()
[debug]#25 0x00000065 in ?? ()
[debug]#26 0x00000000 in ?? ()
[debug]>>>>>>cb_gdb:
----------------------------------------------
NOTE that I see the in the function:
----------------------------------------------
void wxListbook::SetImageList(wxImageList *imageList)
{
const long flagsOld = GetListCtrlFlags();
wxBookCtrlBase::SetImageList(imageList);
const long flagsNew = GetListCtrlFlags();
wxListView * const list = GetListView();
// We may need to change the list control mode if the image list presence
// has changed.
if ( flagsNew != flagsOld )
{
// Preserve the selection which is lost when changing the mode
const int oldSel = GetSelection();
list->SetWindowStyleFlag(flagsNew);
if ( list->InReportView() )
list->InsertColumn(0, wxS("Pages"));
// Restore selection
if ( oldSel != wxNOT_FOUND )
SetSelection(oldSel);
}
list->SetImageList(imageList, wxIMAGE_LIST_NORMAL);
}
----------------------------------------------
The list is just NULL.
BTW: I'm using wx git master HEAD version, which I cloned at 2015-12-27.
I first guess that the function call
m_listbook1->AssignImageList( m_listbook1Images );
should be put after initialization of m_listbook1Images, but If I adjust the code to something like below:
----------------------------------------------
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer( wxVERTICAL );
m_listbook1 = new wxListbook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLB_DEFAULT );
wxSize m_listbook1ImageSize = wxSize( 80,80 );
int m_listbook1Index = 0;
wxImageList* m_listbook1Images = new wxImageList( m_listbook1ImageSize.GetWidth(), m_listbook1ImageSize.GetHeight() );
//m_listbook1->AssignImageList( m_listbook1Images );
wxBitmap m_listbook1Bitmap;
wxImage m_listbook1Image;
m_panel6 = new wxPanel( m_listbook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_listbook1->AddPage( m_panel6, wxT("hihiihi"), false );
m_listbook1Bitmap = wxBitmap( wxT("compiler.png"), wxBITMAP_TYPE_ANY );
m_listbook1Image = m_listbook1Bitmap.ConvertToImage();
m_listbook1Images->Add( m_listbook1Image.Scale( m_listbook1ImageSize.GetWidth(), m_listbook1ImageSize.GetHeight() ) );
m_listbook1->AssignImageList( m_listbook1Images );
m_listbook1->SetPageImage( m_listbook1Index, m_listbook1Index );
m_listbook1Index++;
bSizer1->Add( m_listbook1, 1, wxEXPAND | wxALL, 5 );
this->SetSizer( bSizer1 );
this->Layout();
this->Centre( wxBOTH );
----------------------------------------------
The crash still happens due to the empty pointer. The crash call stack is:
[debug]> bt 30
[debug]#0 0x00d9079c in wxWindowBase::HasFlag (this=0x0, flag=512) at F:\wx\wxWidgets_trunk\include\wx\window.h:668
[debug]#1 0x00d944ee in wxListCtrlBase::IsVirtual (this=0x0) at F:\wx\wxWidgets_trunk\include\wx\listbase.h:453
[debug]#2 0x0070f19a in wxListCtrl::InsertItem (this=0x0, info=...) at F:\wx\wxWidgets_trunk\src\msw\listctrl.cpp:1684
[debug]#3 0x0070f4ae in wxListCtrl::InsertItem (this=0x0, index=0, label=L"hihiihi", imageIndex=-1) at F:\wx\wxWidgets_trunk\src\msw\listctrl.cpp:1751
[debug]#4 0x008295bc in wxListbook::InsertPage (this=0xe891338, n=0, page=0xe88c078, text=L"hihiihi", bSelect=false, imageId=-1) at F:\wx\wxWidgets_trunk\src\generic\listbkg.cpp:325
[debug]#5 0x00cc9d83 in wxBookCtrlBase::AddPage (this=0xe891338, page=0xe88c078, text=L"hihiihi", bSelect=false, imageId=-1) at F:\wx\wxWidgets_trunk\include\wx\bookctrl.h:186
[debug]#6 0x004018c9 in NewDialog::NewDialog (this=0x22f424, parent=0xe8d5d58) at D:\temp\test-listbook-load-xrc2\NewDialog.cpp:210
[debug]#7 0x0040282c in test_listbook_load_xrc2Frame::OnAbout (this=0xe8d5d58, event=...) at D:\temp\test-listbook-load-xrc2\test_listbook_load_xrc2Main.cpp:106
[debug]#8 0x005a387a in wxAppConsoleBase::HandleEvent (this=0xe83b898, handler=0xe8d5d58, func=(void (wxEvtHandler::*)(wxEvtHandler * const, wxEvent &)) 0x402806 <test_listbook_load_xrc2Frame::OnAbout(wxCommandEvent&)>, event=...) at F:\wx\wxWidgets_trunk\src\common\appbase.cpp:657
[debug]#9 0x005a38d6 in wxAppConsoleBase::CallEventHandler (this=0xe83b898, handler=0xe8d5d58, functor=..., event=...) at F:\wx\wxWidgets_trunk\src\common\appbase.cpp:669
[debug]#10 0x0066c4cf in wxEvtHandler::ProcessEventIfMatchesId (entry=..., handler=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1381
[debug]#11 0x0066b507 in wxEventHashTable::HandleEvent (this=0x41308c <test_listbook_load_xrc2Frame::sm_eventHashTable>, event=..., self=0xe8d5d58) at F:\wx\wxWidgets_trunk\src\common\event.cpp:989
[debug]#12 0x0066c93f in wxEvtHandler::TryHereOnly (this=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1578
[debug]#13 0x00cb6c04 in wxEvtHandler::TryBeforeAndHere (this=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\include\wx\event.h:3662
[debug]#14 0x0066c78b in wxEvtHandler::ProcessEventLocally (this=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1511
[debug]#15 0x0066c72c in wxEvtHandler::ProcessEvent (this=0xe8d5d58, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1484
[debug]#16 0x0081084f in wxWindowBase::TryAfter (this=0xe889bf0, event=...) at F:\wx\wxWidgets_trunk\src\common\wincmn.cpp:3468
[debug]#17 0x0066c757 in wxEvtHandler::ProcessEvent (this=0xe889bf0, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1497
[debug]#18 0x0066c9cb in wxEvtHandler::SafelyProcessEvent (this=0xe889bf0, event=...) at F:\wx\wxWidgets_trunk\src\common\event.cpp:1602
[debug]#19 0x0080b89c in wxWindowBase::HandleWindowEvent (this=0xe889bf0, event=...) at F:\wx\wxWidgets_trunk\src\common\wincmn.cpp:1542
[debug]#20 0x007d1419 in wxMenuBase::DoProcessEvent (menu=0xe890d88, event=..., win=0xe8d5d58) at F:\wx\wxWidgets_trunk\src\common\menucmn.cpp:676
[debug]#21 0x007d1362 in wxMenuBase::SendEvent (this=0xe890d88, itemid=101, checked=-1) at F:\wx\wxWidgets_trunk\src\common\menucmn.cpp:646
[debug]#22 0x00794851 in wxFrameBase::ProcessCommand (this=0xe8d5d58, item=0xe890e50) at F:\wx\wxWidgets_trunk\src\common\framecmn.cpp:294
[debug]#23 0x0070585e in wxFrame::HandleCommand (this=0xe8d5d58, id=101, cmd=0, control=0x0) at F:\wx\wxWidgets_trunk\src\msw\frame.cpp:799
[debug]#24 0x00705a58 in wxFrame::MSWWindowProc (this=0xe8d5d58, message=273, wParam=101, lParam=0) at F:\wx\wxWidgets_trunk\src\msw\frame.cpp:849
[debug]#25 0x006da75f in wxWndProc(HWND__*, unsigned int, unsigned int, long)@16 (hWnd=0xd013a, message=273, wParam=101, lParam=0) at F:\wx\wxWidgets_trunk\src\msw\window.cpp:2649
[debug]#26 0x7e418734 in USER32!GetDC () from C:\WINDOWS\system32\user32.dll
[debug]#27 0x000d013a in ?? ()
[debug]#28 0x00000111 in ?? ()
[debug]#29 0x00000065 in ?? ()
[debug](More stack frames follow...)
[debug]>>>>>>cb_gdb:
and it is because in the function:
----------------------------------------------
bool
wxListbook::InsertPage(size_t n,
wxWindow *page,
const wxString& text,
bool bSelect,
int imageId)
{
if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) )
return false;
GetListView()->InsertItem(n, text, imageId);
// if the inserted page is before the selected one, we must update the
// index of the selected page
if ( int(n) <= m_selection )
{
// one extra page added
m_selection++;
GetListView()->Select(m_selection);
GetListView()->Focus(m_selection);
}
if ( !DoSetSelectionAfterInsertion(n, bSelect) )
page->Hide();
UpdateSize();
return true;
}
----------------------------------------------
GetListView() returned a NULL pointer.
So, I guess there are something wrong inside the wxListBook.
BTW: all the above testing C++ code of construction dialog is generated from the wxFormBuilder 3.5 RC1.
asmwarrior