Abnormal program exit

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
vanarieleyen
Knows some wx things
Knows some wx things
Posts: 47
Joined: Thu Aug 29, 2019 3:55 am
Location: China, Shenzhen

Abnormal program exit

Post by vanarieleyen » Sat Dec 21, 2019 2:27 am

I am using nuwen's MingW and have recently updated the toolchain from 16.1 to 17.1. This changed the gcc compiler from 8.2 to 9.2

I compiled wxWidgets-3.1.2 again and re-compiled my current project - everything without problems.

The program that I am developing runs smoothly. The only problem that I am now facing is an abnormal program exit.

I digged a bit deeper into my program and commented out several parts to see when this problem starts to occur.

Below is the basic version that generates the abnormal exit:

Code: Select all

previewFrame::previewFrame(wxWindow* parent,wxWindowID id) {
	//(*Initialize(previewFrame)
	wxMenu* Menu1;
	wxMenu* Menu2;
	wxMenuBar* MenuBar1;
	wxMenuItem* MenuItem1;
	wxMenuItem* MenuItem2;

	Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
	SetClientSize(wxSize(329,335));
	MenuBar1 = new wxMenuBar();
	Menu1 = new wxMenu();
	MenuItem3 = new wxMenuItem(Menu1, ID_MENUITEM1, _("Load"), wxEmptyString, wxITEM_NORMAL);
	Menu1->Append(MenuItem3);
	MenuItem4 = new wxMenuItem(Menu1, ID_MENUITEM2, _("Settings"), wxEmptyString, wxITEM_NORMAL);
	Menu1->Append(MenuItem4);
	MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
	Menu1->Append(MenuItem1);
	MenuBar1->Append(Menu1, _("&File"));
	Menu2 = new wxMenu();
	MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
	Menu2->Append(MenuItem2);
	MenuBar1->Append(Menu2, _("Help"));
	SetMenuBar(MenuBar1);
	Connect(ID_MENUITEM2,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&previewFrame::OnSettings);
	//*)

	// prepare the settings dialog
	settings = new SettingsDlg(this, wxID_ANY, _("Settings"), wxDefaultPosition, wxSize(600, 400));
}
	
class SettingsDlg : public wxDialog {
public:
    SettingsDlg( wxWindow * parent, wxWindowID id, const wxString & title,
                 const wxPoint & pos = wxDefaultPosition,
                 const wxSize & size = wxDefaultSize,
                 long style = wxDEFAULT_DIALOG_STYLE ):
        wxDialog(parent, id, title, pos, size, style) {
        panel = new wxPanel(this, wxID_ANY,
                            wxDefaultPosition,
                            wxSize(300, 300));

	t1 = new wxStaticText(panel, wxID_ANY, _("Background image"), wxPoint(32,32));
	t2 = new wxStaticText(panel, wxID_ANY, _("Preview size"), wxPoint(32,64));
	t3 = new wxStaticText(panel, wxID_ANY, _("Horizontal angles"), wxPoint(32,96));
	t4 = new wxStaticText(panel, wxID_ANY, _("Vertical angles"), wxPoint(32,128));
	t5 = new wxStaticText(panel, wxID_ANY, _("Ambient image"), wxPoint(32,160));
	t6 = new wxStaticText(panel, wxID_ANY, _("Ambient blur"), wxPoint(32,192));
	t7 = new wxStaticText(panel, wxID_ANY, _("Glass plate"), wxPoint(32,224));

        valRange.SetRange(1, 500);
        TextCtrl1 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(136,64), wxSize(56,21), 0, valRange);
        valRange.SetRange(-45, 45);
        TextCtrl2 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(136,96), wxSize(40,21), 0, valRange);
        TextCtrl3 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(208,96), wxSize(40,21), 0, valRange);
        TextCtrl4 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(136,128), wxSize(40,21), 0, valRange);
        TextCtrl5 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(208,128), wxSize(40,21), 0, valRange);
        valRange.SetRange(1, 15);
        TextCtrl6 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(136,192), wxSize(40,21), 0, valRange);

        CheckBox1 = new wxCheckBox(panel, wxID_ANY, wxEmptyString, wxPoint(136,224));

        FilePickerCtrl1 = new wxFilePickerCtrl(panel, wxID_ANY, wxEmptyString, wxEmptyString, wxEmptyString, wxPoint(136,32), wxSize(368,20), wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_USE_TEXTCTRL, wxDefaultValidator);
        FilePickerCtrl2 = new wxFilePickerCtrl(panel, wxID_ANY, wxEmptyString, wxEmptyString, wxEmptyString, wxPoint(136,160), wxSize(368,20), wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_USE_TEXTCTRL, wxDefaultValidator);
        Button = new wxButton(panel, 12345, _("Save"), wxPoint(32,272), wxDefaultSize, 0, wxDefaultValidator);
        Connect(12345,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&OnSaveClick);
    }

    wxIntegerValidator<int> valRange;
    wxCheckBox* CheckBox1;
    wxTextCtrl* TextCtrl1;
    wxTextCtrl* TextCtrl2;
    wxTextCtrl* TextCtrl3;
    wxTextCtrl* TextCtrl4;
    wxTextCtrl* TextCtrl5;
    wxTextCtrl* TextCtrl6;
    wxFilePickerCtrl* FilePickerCtrl1;
    wxFilePickerCtrl* FilePickerCtrl2;

private:
    wxPanel* panel;
    wxStaticText *t1, *t2, *t3, *t4, *t5, *t6, *t7;
    wxButton* Button;
    wxFileConfig *ConfigINI;

    void OnSaveClick(wxCommandEvent& event);		// save the settings
};
When I comment out

Code: Select all

settings = new SettingsDlg(this, wxID_ANY, _("Settings"), wxDefaultPosition, wxSize(600, 400));
the program exits ok.

So I started to comment out parts within the constructor of SettingsDlg.
It appears that the 6 wxTextCtrl's are to blame, when I remove these the program exits without an abnormal program termination message.

Is my SettingsDlg class properly constructed? Or is this a known issue with gcc 9.2.0.

I searched the Internet but couldn't find any mentioning of problems with gcc 9.2

The message that I receive is:
Problem signature:
Problem Event Name: APPCRASH
Application Name: preview.exe
Application Version: 0.0.0.0
Application Timestamp: 5dfd8ff1
Fault Module Name: StackHash_ebd5
Fault Module Version: 6.3.9600.17415
Fault Module Timestamp: 5450559e
Exception Code: c0000374
Exception Offset: PCH_55_FROM_ntdll+0x00000000000911FA
OS Version: 6.3.9600.2.0.0.256.48
Locale ID: 1033
Additional Information 1: ebd5
Additional Information 2: ebd5c0edf1f4c2907c369823ee6d631c
Additional Information 3: ace6
Additional Information 4: ace62d7582b2ce32e568489cbb5a8ad6
I looked up the exception code and found out that is a heap corruption, so there must be something that is not properly deallocated but I can't find what...

vanarieleyen
Knows some wx things
Knows some wx things
Posts: 47
Joined: Thu Aug 29, 2019 3:55 am
Location: China, Shenzhen

Re: Abnormal program exit

Post by vanarieleyen » Sat Dec 21, 2019 5:38 am

I have made the most simple program that also shows the error.

In Code::Blocks I started a new project and placed the block with the textctrl's from my original program in the constructor:

The resulting program is as follows:

Code: Select all

/***************************************************************
 * Name:      testMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    Arie van Leyen ()
 * Created:   2019-12-21
 * Copyright: Arie van Leyen ()
 * License:
 **************************************************************/

#include "testMain.h"
#include <wx/msgdlg.h>

#include <wx/valnum.h>
#include <wx/textctrl.h>

//(*InternalHeaders(testFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
	short_f, long_f
};

wxString wxbuildinfo(wxbuildinfoformat format) {
	wxString wxbuild(wxVERSION_STRING);

	if (format == long_f ) {
#if defined(__WXMSW__)
		wxbuild << _T("-Windows");
#elif defined(__UNIX__)
		wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
		wxbuild << _T("-Unicode build");
#else
		wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
	}

	return wxbuild;
}

//(*IdInit(testFrame)
const long testFrame::idMenuQuit = wxNewId();
const long testFrame::idMenuAbout = wxNewId();
const long testFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(testFrame,wxFrame)
	//(*EventTable(testFrame)
	//*)
END_EVENT_TABLE()

testFrame::testFrame(wxWindow* parent,wxWindowID id) {
	//(*Initialize(testFrame)
	wxMenu* Menu1;
	wxMenu* Menu2;
	wxMenuBar* MenuBar1;
	wxMenuItem* MenuItem1;
	wxMenuItem* MenuItem2;

	Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
	MenuBar1 = new wxMenuBar();
	Menu1 = new wxMenu();
	MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
	Menu1->Append(MenuItem1);
	MenuBar1->Append(Menu1, _("&File"));
	Menu2 = new wxMenu();
	MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
	Menu2->Append(MenuItem2);
	MenuBar1->Append(Menu2, _("Help"));
	SetMenuBar(MenuBar1);
	StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
	int __wxStatusBarWidths_1[1] = { -1 };
	int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
	StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
	StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
	SetStatusBar(StatusBar1);

	Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&testFrame::OnQuit);
	Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&testFrame::OnAbout);
	//*)

	wxPanel *panel = new wxPanel(this, wxID_ANY,
	                             wxDefaultPosition,
	                             wxSize(300, 300));
	wxIntegerValidator<int> valRange;

	wxTextCtrl* TextCtrl1;
	wxTextCtrl* TextCtrl2;
	wxTextCtrl* TextCtrl3;
	wxTextCtrl* TextCtrl4;
	wxTextCtrl* TextCtrl5;
	wxTextCtrl* TextCtrl6;

	valRange.SetRange(1, 500);
	TextCtrl1 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(136,64), wxSize(56,21), 0, valRange);
	valRange.SetRange(-45, 45);
	TextCtrl2 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(136,96), wxSize(40,21), 0, valRange);
	TextCtrl3 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(208,96), wxSize(40,21), 0, valRange);
	TextCtrl4 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(136,128), wxSize(40,21), 0, valRange);
	TextCtrl5 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(208,128), wxSize(40,21), 0, valRange);
	valRange.SetRange(1, 15);
	TextCtrl6 = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(136,192), wxSize(40,21), 0, valRange);
}

testFrame::~testFrame() {
	//(*Destroy(testFrame)
	//*)
}

void testFrame::OnQuit(wxCommandEvent& event) {
	Close();
}

void testFrame::OnAbout(wxCommandEvent& event) {
	wxString msg = wxbuildinfo(long_f);
	wxMessageBox(msg, _("Welcome to..."));
}
When I compile and run this it has no problems.

When I close the program I get the following message:
Problem signature:
Problem Event Name: APPCRASH
Application Name: test.exe
Application Version: 0.0.0.0
Application Timestamp: 5dfdac17
Fault Module Name: StackHash_21c8
Fault Module Version: 6.3.9600.17415
Fault Module Timestamp: 5450559e
Exception Code: c0000374
Exception Offset: PCH_55_FROM_ntdll+0x00000000000911FA
OS Version: 6.3.9600.2.0.0.256.48
Locale ID: 1033
Additional Information 1: 21c8
Additional Information 2: 21c8e2d2d46a23504b52407d03d48343
Additional Information 3: 810a
Additional Information 4: 810a0d19da18b5d2edbba80aaa69ab8f
I now start to suspect the build of wxWidgets.
I have done the following to build wxWidgets (3.1.2):
  • first go to: c:\wxWidgets.3.2.1\build\msw
  • clean the sources: make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release clean
  • build a release: make -f makefile.gcc SHARED=1 MONOLITHIC=1 UNICODE=1 BUILD=release
I use MinGW from the nuwen distribution version 17.1: https://nuwen.net/mingw.html
This distribution includes GCC 9.2.0

When I use the old verion of MinGW (nuwen 16.1) the compiler version is 8.2.0 - this version has no problems.

During the build of wxWidgets I saw a lot of warnings. I checked on the internet and it seems that GCC 9.2.0 does more checks and as a result gives more warnings.

Can it be that I need to change the way I am building wxWidgets with gcc 9.2.0?

I have attached the most simple project that gives this error.
Attachments
test.zip
(430.38 KiB) Downloaded 16 times

alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Tue Oct 18, 2016 2:31 pm

Re: Abnormal program exit

Post by alys666 » Sat Dec 21, 2019 7:49 am

run your code under debugger. and do not experiment with compilers and build versions.
problem is somewhere in your code, not in compiler :)
if program crashes on exit - it cannot finalize your objects. so it's somehow connected with destructors and finalization order.
if you use codeblocks - set debug mode and debug. debugger must show you at least stack state of a crash point.
it's what you need.
ubuntu 16.04, wxWidgets 3.0.4

vanarieleyen
Knows some wx things
Knows some wx things
Posts: 47
Joined: Thu Aug 29, 2019 3:55 am
Location: China, Shenzhen

Re: Abnormal program exit

Post by vanarieleyen » Sat Dec 21, 2019 8:07 am

Yes, I know it is better to stick with my old tool chain.

However, you say that it must be in my code. But then how can you explain the problems that I face in the test project that I have attached?

To generate this project I have chosen 'new project' in code::blocks and only placed 2 wxTextControls on a wxPanel - nothing more.

After compiling it works, but I get the message after closing the program.

I have also build it in de debugger mode and run it in the gdb using the following commands:
gdb test.exe
(gdb) run
(now close the window)
(gdb) warning: critical error detected c0000374
(gdb) Program received signal SIGTRAP, Trace/breakpoint trap.
(gdb) 0x........ in ?? <>

The error seems to be a heap corruption, but how is that possible when I have only placed those two textcontrols and not a single line of extra code?

alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Tue Oct 18, 2016 2:31 pm

Re: Abnormal program exit

Post by alys666 » Sat Dec 21, 2019 8:47 am

for start.
1.you must use some coding conventions in your code.
names of formal parameters, local variables, global variables are in mess, and this is not readable.
for example i use such a conventions:
_name - object field
fname - "formal name" - formal function parameter-> func(type fs)
lname - local function variable
Name - global variable.
2. do not use <Connect> to bind handlers, use Bind.
3. do not use old style type conversions (type)... because it's risky.
4. do not write headers, if you do not plan to use declared objects in different source files.
ubuntu 16.04, wxWidgets 3.0.4

alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Tue Oct 18, 2016 2:31 pm

Re: Abnormal program exit

Post by alys666 » Sat Dec 21, 2019 8:52 am

if it was a heap corruption... then it could be an object disposed twice(may added twice to different parents?), or memory block was corrupted due writing out of bound index of array or wrong pointer, or something kinda this.
ubuntu 16.04, wxWidgets 3.0.4

vanarieleyen
Knows some wx things
Knows some wx things
Posts: 47
Joined: Thu Aug 29, 2019 3:55 am
Location: China, Shenzhen

Re: Abnormal program exit

Post by vanarieleyen » Sat Dec 21, 2019 9:05 am

As I told you, I didn't write any line of code.

I let Code::Blocks generate a wxWidgets skeleton for me and I place a panel and 2 textcontrolls on it.

If I understand it well, you are suggesting that Code::Blocks doesn't generate very nice code. I agree, but I don't think in this case it is the problem.

Kvaz1r
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 216
Joined: Tue Jun 07, 2016 1:07 pm

Re: Abnormal program exit

Post by Kvaz1r » Sat Dec 21, 2019 9:55 am

Your code runs without crash for me (I use VS), but you can reduce code even more. What if your frame won't contains any control? What if you remove only status bar?

User avatar
doublemax
Moderator
Moderator
Posts: 14972
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Abnormal program exit

Post by doublemax » Sat Dec 21, 2019 10:30 am

The problem is not in the code, it's a build issue. As you're linking dynamically, are you sure the exe is loading the correct DLL and not an old one?

Can you switch to static linking for a test?
Use the source, Luke!

Post Reply