I have been trying to chase out this random bug, and not sure where to look now, so would be great with some more experienced eye's on it.
I have this wxWidget c++ VS app that will randomly throw an exception at initialization. In the "OnInit" function it will randomly throw an exception in either memcpy.asm or init.cpp. That said the throw is always the same:
"Exception thrown at 0x7B0232AE (vcruntime140.dll) in SerialViewer.exe: 0xC0000005: Access violation reading location 0xA7C28FDB."
Here is what i believe to be the relevant code, please tell me if there is anything else you'd like to see.
cApp.h:
Code: Select all
#pragma once
#include <wx/wxprec.h>
#include "cMain.h"
class cApp : public wxApp
{
public:
cMain* m_frame1=nullptr;
public:
virtual bool OnInit();
};
Code: Select all
#include "cApp.h"
wxIMPLEMENT_APP(cApp);
bool cApp::OnInit()
{
m_frame1=new cMain();
m_frame1->SetBackgroundColour(wxColour(33,37,43));
m_frame1->Show(true);
return true;
}
Code: Select all
cMain::cMain() : wxFrame(nullptr,wxID_ANY,"SerialViewer2.0",wxPoint(30,30),wxSize(850,800))
{
wxPanel *topBar=new wxPanel(this,wxID_ANY,wxDefaultPosition,wxDefaultSize);
topBar->SetBackgroundColour(secondaryColour1);
wxPanel *mainPanel=new wxPanel(this,wxID_ANY,wxDefaultPosition,wxDefaultSize);
mainPanel->SetBackgroundColour(secondaryColour1);
wxPanel *sideBar=new wxPanel(this,wxID_ANY,wxDefaultPosition,wxDefaultSize);
sideBar->SetBackgroundColour(secondaryColour1);
wxPanel *bottomBar=new wxPanel(this,wxID_ANY,wxDefaultPosition,wxDefaultSize);
bottomBar->SetBackgroundColour(secondaryColour1);
wxSizer *leftGroupSz=new wxBoxSizer(wxVERTICAL);
leftGroupSz->Add(topBar,0,wxEXPAND | wxALL,5);
leftGroupSz->Add(mainPanel,1,wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT,5);
wxSizer *mainGroupSz=new wxBoxSizer(wxHORIZONTAL);
mainGroupSz->Add(leftGroupSz,1,wxEXPAND,0);
mainGroupSz->Add(sideBar,0,wxEXPAND | wxTOP | wxRIGHT | wxBOTTOM,5);
wxBoxSizer *allSz=new wxBoxSizer(wxVERTICAL);
allSz->Add(mainGroupSz,1,wxEXPAND,0);
allSz->Add(bottomBar,0,wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT,5);
txtWrite=new wxTextCtrl(topBar,wxID_ANY,"",wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER);
txtWrite->SetBackgroundColour(secondaryColour2);
txtWrite->SetForegroundColour(txtColour1);
txtWrite->SetFont(font1);
wxSizer *txtWriteSz=new wxBoxSizer(wxVERTICAL);
txtWriteSz->Add(txtWrite,0,wxEXPAND | wxTOP | wxBOTTOM,5);
topBar->SetSizerAndFit(txtWriteSz);
txtRead=new wxTextCtrl(mainPanel,wxID_ANY,"",wxDefaultPosition,wxSize(500,450),wxTE_MULTILINE | wxTE_READONLY);
txtRead->SetFont(font2);
txtRead->SetBackgroundColour(secondaryColour2);
txtRead->SetForegroundColour(txtColour1);
wxSizer *txtReadSz=new wxBoxSizer(wxVERTICAL);
txtReadSz->Add(txtRead,1,wxEXPAND,0);
mainPanel->SetSizer(txtReadSz);
btnConnect=new wxButton(sideBar,wxID_ANY,"Connect",wxDefaultPosition,wxSize(100,50));
cbxBaud=new wxComboBox(sideBar,wxID_ANY,defBaudRate,wxDefaultPosition,wxSize(130,25),cbxBaudNum,cbxBaudSel,wxCB_READONLY);
cbxPort=new wxComboBox(sideBar,wxID_ANY,"",wxDefaultPosition,wxSize(130,25));
chkReset=new wxCheckBox(sideBar,wxID_ANY,"Auto DTR Reset",wxDefaultPosition,wxSize(100,25));
wxStaticText *tlaBaud=new wxStaticText(sideBar,wxID_ANY,"Baud Rate",wxDefaultPosition,wxDefaultSize);
wxStaticText *tlaPort=new wxStaticText(sideBar,wxID_ANY,"Port Select",wxDefaultPosition,wxDefaultSize);
tlaBaud->SetForegroundColour(txtColour1);
tlaPort->SetForegroundColour(txtColour1);
chkReset->SetForegroundColour(txtColour1);
wxSizer *mainSettSz=new wxBoxSizer(wxVERTICAL);
mainSettSz->Add(btnConnect,0,wxEXPAND | wxBOTTOM,10);
mainSettSz->Add(tlaBaud,0,wxEXPAND,0);
mainSettSz->Add(cbxBaud,0,wxEXPAND | wxBOTTOM,10);
mainSettSz->Add(tlaPort,0,wxEXPAND,0);
mainSettSz->Add(cbxPort,0,wxEXPAND | wxBOTTOM,10);
mainSettSz->Add(chkReset,0,wxEXPAND | wxTOP | wxBOTTOM,10);
tlaConnected=new wxStaticText(sideBar,wxID_ANY,"Unconnected",wxDefaultPosition,wxDefaultSize,wxALIGN_CENTER_HORIZONTAL | wxST_NO_AUTORESIZE);
tlaConnected->SetForegroundColour(txtColour2);
wxSizer *tlaConnectedAlignSz=new wxBoxSizer(wxHORIZONTAL);
tlaConnectedAlignSz->Add(tlaConnected,1,wxALIGN_BOTTOM,0);
wxSizer *sideBarSz=new wxBoxSizer(wxVERTICAL);
sideBarSz->Add(mainSettSz,1,wxEXPAND | wxLEFT | wxTOP | wxRIGHT,5);
sideBarSz->Add(tlaConnectedAlignSz,0,wxEXPAND,0);
sideBar->SetSizerAndFit(sideBarSz);
btnClear=new wxButton(bottomBar,wxID_ANY,"Clear",wxDefaultPosition,wxDefaultSize);
chkScroll=new wxCheckBox(bottomBar,wxID_ANY,"Auto Scroll",wxDefaultPosition,wxDefaultSize);
chkClear=new wxCheckBox(bottomBar,wxID_ANY,"Auto Clear",wxDefaultPosition,wxDefaultSize);
chkScroll->SetForegroundColour(txtColour1);
chkClear->SetForegroundColour(txtColour1);
wxSizer *otherSettSz=new wxBoxSizer(wxHORIZONTAL);
otherSettSz->Add(btnClear,0,wxEXPAND | wxALL,5);
otherSettSz->Add(chkScroll,0,wxEXPAND | wxALL,5);
otherSettSz->Add(chkClear,0,wxEXPAND | wxALL,5);
wxSizer *bottomBarSz=new wxBoxSizer(wxHORIZONTAL);
bottomBarSz->Add(otherSettSz,1,wxALIGN_LEFT,0);
bottomBar->SetSizerAndFit(bottomBarSz);
this->SetSizer(allSz);
this->SetMinSize(wxSize(350,360));
chkReset->SetValue(true);
chkScroll->SetValue(true);
chkClear->SetValue(true);
updateComPorts();
menubar=new wxMenuBar;
file=new wxMenu;
file->Append(wxID_SETUP,wxT("&Port settings"));
file->Append(wxID_ABOUT,wxT("&About"));
file->Append(wxID_REFRESH,wxT("Refresh Ports"));
file->Append(wxID_PRINT_SETUP,wxT("List Settings"));
menubar->Append(file,wxT("&File"));
SetMenuBar(menubar);
cbxBaud->Bind(wxEVT_COMBOBOX,&cMain::baudChange,this);
cbxPort->Bind(wxEVT_COMBOBOX,&cMain::comPortChange,this);
btnConnect->Bind(wxEVT_BUTTON,&cMain::serialConnect,this);
btnClear->Bind(wxEVT_BUTTON,&cMain::clearReadTxt,this);
txtWrite->Bind(wxEVT_TEXT_ENTER,&cMain::onTxtWriteSend,this);
chkScroll->Bind(wxEVT_CHECKBOX,&cMain::chkScrollChange,this);
Bind(wxEVT_MENU,&cMain::menuSettings,this,wxID_SETUP);
Bind(wxEVT_MENU,&cMain::menuAbout,this,wxID_ABOUT);
Bind(wxEVT_MENU,&cMain::menuUpdatePorts,this,wxID_REFRESH);
Bind(wxEVT_MENU,&cMain::menuListSettings,this,wxID_PRINT_SETUP);
Bind(PT_WRITE_EVT,&cMain::printReadDataEvt,this,ptWriteEvtId);
Bind(SC_ERROR_EVT,&cMain::serialThreadErrorEvt,this,scErrorEvtId);
}
Windows 10
Visual studio 2019
wxWidgets 3.1.5
//Benji