From 19eabfc700865395edbc68011b419913e9f86532 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Sat, 1 Mar 2014 22:24:25 -0500 Subject: [PATCH] fix memory error open/save dialog should work now --- src/nebedit/nebedit.cpp | 60 ++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/src/nebedit/nebedit.cpp b/src/nebedit/nebedit.cpp index 0f12e5c..0f485ef 100644 --- a/src/nebedit/nebedit.cpp +++ b/src/nebedit/nebedit.cpp @@ -91,7 +91,7 @@ * $NoKeywords: $ */ -#if 0 + #include "wx/wxprec.h" #ifndef WX_PRECOMP @@ -99,7 +99,6 @@ #endif #include "wx/filedlg.h" -#endif #include #include @@ -191,6 +190,19 @@ int Nebedit_running = 1; extern void project_2d_onto_sphere(vector *, float, float); +class MyApp: public wxApp +{ +public: + virtual bool OnInit(); +}; + +bool MyApp::OnInit() +{ + return false; +} + +IMPLEMENT_APP_NO_MAIN(MyApp) + void create_default_neb() { int i,j; @@ -350,29 +362,45 @@ void nebedit_close() void save_nebula() { -#if 0 - wxFileDialog saveFileDialog(NULL, _("Save Nebula File"), wxEmptyString, + wxTheApp->OnInit(); + + wxFileDialog *saveFileDialog = new wxFileDialog(NULL, _("Save Nebula File"), wxEmptyString, wxEmptyString, _("Nebula Files (*.neb)|*.neb"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT); - if (saveFileDialog.Show() == wxID_OK) { - save_nebula_sub(saveFileDialog.GetPath().ToAscii()); + wxTheApp->SetTopWindow(saveFileDialog); + + if (saveFileDialog->ShowModal() == wxID_OK) { + save_nebula_sub(saveFileDialog->GetPath().ToAscii()); } -#endif + + saveFileDialog->Destroy(); + + wxTheApp->OnRun(); + wxTheApp->OnExit(); } void load_nebula() { int create_default = 1; -#if 0 - wxFileDialog openFileDialog(NULL, _("Open Nebula File"), wxEmptyString, + + wxTheApp->OnInit(); + + wxFileDialog *openFileDialog = new wxFileDialog(NULL, _("Open Nebula File"), wxEmptyString, wxEmptyString, _("Nebula Files (*.neb)|*.neb"), wxFD_OPEN|wxFD_FILE_MUST_EXIST); - if (openFileDialog.Show() == wxID_OK) { - create_default = !load_nebula_sub(openFileDialog.GetPath().ToAscii()); + wxTheApp->SetTopWindow(openFileDialog); + + if (openFileDialog->ShowModal() == wxID_OK) { + create_default = !load_nebula_sub(openFileDialog->GetPath().ToAscii()); } -#endif + + openFileDialog->Destroy(); + + wxTheApp->OnRun(); + wxTheApp->OnExit(); + if ( create_default ) { create_default_neb(); } @@ -383,7 +411,7 @@ void load_nebula() void nebula_init() { if ( nebula_inited ) return; - memset(Selected, 0, sizeof(BOOL)*MAX_POINTS); + memset(Selected, 0, sizeof(bool)*MAX_POINTS); nebula_inited++; create_default_neb(); @@ -903,6 +931,10 @@ int main(int argc, char *argv[]) nebula_init(); + wxApp::SetInstance( new MyApp() ); + + wxEntryStart(argc, argv); + //bool some_selected = false; while(1) { @@ -1032,6 +1064,8 @@ int main(int argc, char *argv[]) nebedit_close(); + wxEntryCleanup(); + return 0; } -- 2.39.2