I've read this, but I still don't understand what I did wrong with the code.
Here's the bmNewFromImageDialog.h
, the class that extends wxDialog
.
#ifndef BMNEWFROMIMAGEDIALOG_H
#define BMNEWFROMIMAGEDIALOG_H
#include "./../utils/includer.h" // includes a bunch of wx-related files
class bmNewFromImageDialog : public wxDialog {
public:
wxBoxSizer *mainVBox, *flagHBox, *OKCancelHBox;
wxStaticBox *flagsSBox;
wxButton *OKButton, *cancelButton;
wxRadioButton *GT0RadioButton;
bmNewFromImageDialog() {}
bmNewFromImageDialog(wxWindow *parent);
void init();
};
#endif
Here's the bmNewFromImageDialog.cpp
.
#include "./bmNewFromImageDialog.h"
#include "./../utils/includer.h"
bmNewFromImageDialog::bmNewFromImageDialog(wxWindow *parent) : wxDialog(parent, -1, wxT("new image..."), wxDefaultPosition, wxDefaultSize) {
init();
}
void bmNewFromImageDialog::init() {
mainVBox = new wxBoxSizer(wxVERTICAL);
flagHBox = new wxBoxSizer(wxHORIZONTAL);
OKCancelHBox = new wxBoxSizer(wxHORIZONTAL);
flagsSBox = new wxStaticBox(this, -1, wxT("Color flags"), wxPoint(0, 0), wxDefaultSize);
GT0RadioButton = new wxRadioButton(this, -1, wxT(">0: 3 channels"), wxPoint(0, 0));
flagsSBox->AddChild(GT0RadioButton);
flagHBox->Add(flagsSBox, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 10);
OKButton = new wxButton(this, wxID_OK, wxT("OK"), wxDefaultPosition, wxSize(100, 40));
cancelButton = new wxButton(this, wxID_CANCEL, wxT("cancel"), wxDefaultPosition, wxSize(100, 40));
OKCancelHBox->Add(OKButton, 1);
OKCancelHBox->Add(cancelButton, 1, wxLEFT, 5);
mainVBox->Add(flagHBox, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 10);
mainVBox->Add(OKCancelHBox, 0, wxALIGN_CENTER | wxBOTTOM, 10);
SetSizer(mainVBox);
Center();
}
and this is how I use the dialog in code:
bmNewFromImageDialog *newDialog = new bmNewFromImageDialog(this);
newDialog->ShowModal();
delete newDialog;
I constantly get an unhandled memory exception error at runtime when I close / click OK / click Cancel on that bmNewFromImageDialog
. How should I fix this?
EDIT
@sir-digby-chicken-caesar I tried the .Destroy()
and the stack solution, but there's still the same error: