Crash on Windows

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Crash on Windows

Post 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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Crash on Windows

Post 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
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Crash on Windows

Post 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.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crash on Windows

Post 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.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Crash on Windows

Post 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.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crash on Windows

Post 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.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Crash on Windows

Post by ONEEYEMAN »

doublemax,
I use MSVC 2017 Community on Win 8.1.
Do you happen to have an SQLite db somewhere?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crash on Windows

Post by doublemax »

ONEEYEMAN wrote: Mon Dec 23, 2019 1:29 pmDo you happen to have an SQLite db somewhere?
Just any SQLite db? Sure.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Crash on Windows

Post by ONEEYEMAN »

doublemax,
Sent by PM.

Thank you.
Post Reply