Page 1 of 1

Crash on Windows

Posted: Thu Dec 12, 2019 4:13 pm
by ONEEYEMAN
Hi, ALL,
I'm trying to create an application based on the MDI doc-view paradigm.

The application starts up with an empty window and the toolbar.
When the user click on one of the tools in the toolbar the MDI child window with the view is created and the user goes thru some modal dialogs.
Based on the user responce in those dialogs I am changing the layout of the view and changing the menu bar/toolbar.

So basically I am calling this:

Code: Select all

wxMenuBar *menuBar = dynamic_cast<MDIParentFrame *>( GetMainWindow() )->GetMenuBar();
for( size_t i = menuBar->GetCount() - 2; i > 0; --i )
  {
      auto *menu = menuBar->Remove( i );
      delete menu;
      menu = nullptr;
  }
 menuBar->Insert( 1, <new menu> );
Everything works as expected, however when I try to close the main frame I am getting Windows exception in the menu bar destructor on Windows. On Linux everything works.

So, this is what happens.
Initially I have a menu bar like this:
File <menu1> <menu2> <menu3> Windows Help
After executing the code above it becomes:
File <menu4> Windows Help
Now the sample does not assign the menu pointer to become "nullptr" after deletion.

Could this be a culprit?

Thank you.

Re: Crash on Windows

Posted: Fri Dec 20, 2019 1:38 am
by ONEEYEMAN
Hi,
The backtrace on the crash follows

Code: Select all

>	wxmsw313ud_core_vc_custom.dll!wxMenuBarBase::~wxMenuBarBase() Line 857	C++
 	wxmsw313ud_core_vc_custom.dll!wxMenuBar::~wxMenuBar() Line 877	C++
 	docview.exe!wxMenuBar::`scalar deleting destructor'(unsigned int)	C++
 	wxmsw313ud_core_vc_custom.dll!wxDELETE<wxMenuBar>(wxMenuBar * & ptr) Line 861	C++
 	wxmsw313ud_core_vc_custom.dll!wxFrameBase::DeleteAllBars() Line 187	C++
 	wxmsw313ud_core_vc_custom.dll!wxFrameBase::~wxFrameBase() Line 171	C++
 	wxmsw313ud_core_vc_custom.dll!wxFrame::~wxFrame() Line 168	C++
 	wxmsw313ud_core_vc_custom.dll!wxMDIParentFrameBase::~wxMDIParentFrameBase() Line 60	C++
 	wxmsw313ud_core_vc_custom.dll!wxMDIParentFrame::~wxMDIParentFrame() Line 247	C++
 	wxmsw313ud_core_vc_custom.dll!wxDocParentFrameAny<wxMDIParentFrame>::~wxDocParentFrameAny<wxMDIParentFrame>()	C++
 	wxmsw313ud_core_vc_custom.dll!wxDocMDIParentFrame::~wxDocMDIParentFrame()	C++
 	docview.exe!MainFrame::~MainFrame() Line 132	C++
 	docview.exe!MainFrame::`scalar deleting destructor'(unsigned int)	C++
 	wxbase313ud_vc_custom.dll!wxAppConsoleBase::DeletePendingObjects() Line 637	C++
 	wxbase313ud_vc_custom.dll!wxAppConsoleBase::ProcessIdle() Line 445	C++
 	wxmsw313ud_core_vc_custom.dll!wxAppBase::ProcessIdle() Line 397	C++
 	wxbase313ud_vc_custom.dll!wxEventLoopBase::ProcessIdle() Line 107	C++
 	wxbase313ud_vc_custom.dll!wxEventLoopManual::DoRun() Line 273	C++
 	wxbase313ud_vc_custom.dll!wxEventLoopBase::Run() Line 90	C++
 	wxbase313ud_vc_custom.dll!wxAppConsoleBase::MainLoop() Line 380	C++
 	wxbase313ud_vc_custom.dll!wxAppConsoleBase::OnRun() Line 301	C++
 	wxmsw313ud_core_vc_custom.dll!wxAppBase::OnRun() Line 335	C++
 	wxbase313ud_vc_custom.dll!wxEntryReal(int & argc, wchar_t * * argv) Line 507	C++
 	wxbase313ud_vc_custom.dll!wxEntry(int & argc, wchar_t * * argv) Line 184	C++
 	wxmsw313ud_core_vc_custom.dll!wxEntry(HINSTANCE__ * hInstance, HINSTANCE__ * __formal, char * __formal, int nCmdShow) Line 305	C++
 	docview.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 63	C++
 	docview.exe!invoke_main() Line 107	C++
 	docview.exe!__scrt_common_main_seh() Line 283	C++
 	docview.exe!__scrt_common_main() Line 326	C++
 	docview.exe!WinMainCRTStartup() Line 17	C++
 	kernel32.dll!750b6a14()	Unknown
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	
 	ntdll.dll!7718ad8f()	Unknown
 	ntdll.dll!7718ad5a()	Unknown

Re: Crash on Windows

Posted: Sat Dec 21, 2019 5:46 am
by ONEEYEMAN
So, I did a little experimenting.

Code: Select all

    wxMenuBar *bar = m_parent->GetMenuBar();
    if( queryType == 2 )
    {
        for( int i = bar->GetMenuCount() - 2; i > 0; i-- )
        {
            auto *menu = bar->Remove( i );
            delete menu;
        }
        auto *designMenu = new wxMenu;
        bar->Insert( 1, designMenu, _( "Design" ) );
That code above produces crash.
If I comment out the last 2 lines the program does not crash.

I tried to reproduce it in the docview sample, but failed.

When I call this code I have 6 menus in the menu bar plus "Window" menu.

Any idea of what might be the problem?

Thank you.

Re: Crash on Windows

Posted: Sat Dec 21, 2019 9:32 am
by doublemax
I can't spot anything wrong in the code. If this is only about the menu deleting / inserting, it should be possible to create a small sample that shows the problem.

Re: Crash on Windows

Posted: Mon Dec 23, 2019 4:16 am
by ONEEYEMAN
doublemax,
I triedto run my code and see if you can reproduce it? to modify the docview sample, but it still behave normally.

Would it be possible for you to run my code and see if you could reproduce it?

I can give you the data and reproduction steps (BTW - which MSVC version do you use for wx development?).

If not I will continue trying - maybe see what is different between my code and the sample (if anything).

Thank you.

Re: Crash on Windows

Posted: Mon Dec 23, 2019 10:39 am
by doublemax
Would it be possible for you to run my code and see if you could reproduce it?
Sure.
I can give you the data and reproduction steps (BTW - which MSVC version do you use for wx development?).
VS2013. But i could get 2015 or 2017 too. And 2019 Community.

Re: Crash on Windows

Posted: Mon Dec 23, 2019 1:29 pm
by ONEEYEMAN
doublemax,
I use MSVC 2017 Community on Win 8.1.
Do you happen to have an SQLite db somewhere?

Thank you.

Re: Crash on Windows

Posted: Mon Dec 23, 2019 1:45 pm
by doublemax
ONEEYEMAN wrote:
Mon Dec 23, 2019 1:29 pm
Do you happen to have an SQLite db somewhere?
Just any SQLite db? Sure.

Re: Crash on Windows

Posted: Tue Dec 24, 2019 3:04 pm
by ONEEYEMAN
doublemax,
Sent by PM.

Thank you.