- some basic error catching to avoid application crash when errors occur

This commit is contained in:
Mark Vejvoda
2011-01-20 19:47:33 +00:00
parent 685c338f97
commit d32a52a072

View File

@@ -225,21 +225,34 @@ void MainWindow::onClose(wxCloseEvent &event){
// for the mousewheel // for the mousewheel
void MainWindow::onMouseWheelDown(wxMouseEvent &event) { void MainWindow::onMouseWheelDown(wxMouseEvent &event) {
try {
wxPaintEvent paintEvent; wxPaintEvent paintEvent;
zoom*= 1.1f; zoom*= 1.1f;
zoom= clamp(zoom, 0.1f, 10.0f); zoom= clamp(zoom, 0.1f, 10.0f);
onPaint(paintEvent); onPaint(paintEvent);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMouseWheelUp(wxMouseEvent &event) { void MainWindow::onMouseWheelUp(wxMouseEvent &event) {
try {
wxPaintEvent paintEvent; wxPaintEvent paintEvent;
zoom*= 0.90909f; zoom*= 0.90909f;
zoom= clamp(zoom, 0.1f, 10.0f); zoom= clamp(zoom, 0.1f, 10.0f);
onPaint(paintEvent); onPaint(paintEvent);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMouseMove(wxMouseEvent &event){ void MainWindow::onMouseMove(wxMouseEvent &event){
try {
int x= event.GetX(); int x= event.GetX();
int y= event.GetY(); int y= event.GetY();
wxPaintEvent paintEvent; wxPaintEvent paintEvent;
@@ -258,8 +271,14 @@ void MainWindow::onMouseMove(wxMouseEvent &event){
lastX= x; lastX= x;
lastY= y; lastY= y;
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::OnChangeColor(wxCommandEvent &event) { void MainWindow::OnChangeColor(wxCommandEvent &event) {
try {
//wxColour color = colorPicker->GetColour(); //wxColour color = colorPicker->GetColour();
wxColourData data; wxColourData data;
data.SetChooseFull(true); data.SetChooseFull(true);
@@ -282,12 +301,16 @@ void MainWindow::OnChangeColor(wxCommandEvent &event) {
//myWindow->Refresh(); //myWindow->Refresh();
} }
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileLoad(wxCommandEvent &event){ void MainWindow::onMenuFileLoad(wxCommandEvent &event){
try {
string fileName; string fileName;
fileDialog->SetWildcard(wxT("G3D files (*.g3d)|*.g3d")); fileDialog->SetWildcard(wxT("G3D files (*.g3d)|*.g3d"));
fileDialog->SetMessage(wxT("Selecting Glest Model for current view.")); fileDialog->SetMessage(wxT("Selecting Glest Model for current view."));
if(fileDialog->ShowModal()==wxID_OK){ if(fileDialog->ShowModal()==wxID_OK){
@@ -296,8 +319,14 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event){
} }
isControlKeyPressed = false; isControlKeyPressed = false;
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
try {
string fileName; string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml")); fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
@@ -314,8 +343,14 @@ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
} }
isControlKeyPressed = false; isControlKeyPressed = false;
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){ void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){
try {
string fileName; string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml")); fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
@@ -332,8 +367,14 @@ void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){
} }
isControlKeyPressed = false; isControlKeyPressed = false;
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){ void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){
try {
string fileName; string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml")); fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
@@ -349,10 +390,16 @@ void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){
loadSplashParticle(path); loadSplashParticle(path);
} }
isControlKeyPressed = false; isControlKeyPressed = false;
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method? } // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method?
void MainWindow::onMenuFileSaveScreenshot(wxCommandEvent &event) { void MainWindow::onMenuFileSaveScreenshot(wxCommandEvent &event) {
try {
string path = "screens/"; string path = "screens/";
if(isdir(path.c_str()) == true) { if(isdir(path.c_str()) == true) {
//Config &config= Config::getInstance(); //Config &config= Config::getInstance();
@@ -373,8 +420,14 @@ void MainWindow::onMenuFileSaveScreenshot(wxCommandEvent &event) {
} }
} }
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileClearAll(wxCommandEvent &event) { void MainWindow::onMenuFileClearAll(wxCommandEvent &event) {
try {
modelPathList.clear(); modelPathList.clear();
particlePathList.clear(); particlePathList.clear();
particleProjectilePathList.clear(); particleProjectilePathList.clear();
@@ -403,6 +456,11 @@ void MainWindow::onMenuFileClearAll(wxCommandEvent &event) {
timer->Start(100); timer->Start(100);
isControlKeyPressed = false; isControlKeyPressed = false;
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileExit(wxCommandEvent &event) { void MainWindow::onMenuFileExit(wxCommandEvent &event) {
Close(); Close();
@@ -513,7 +571,7 @@ void MainWindow::loadParticle(string path) {
} }
catch(std::runtime_error e) { catch(std::runtime_error e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
wxMessageBox( ToUnicode(e.what()), wxT("Not a Mega-Glest particle XML file, or broken"), wxICON_ERROR); wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
} }
timer->Start(100); timer->Start(100);
} }
@@ -619,7 +677,7 @@ void MainWindow::loadProjectileParticle(string path) {
} }
catch(std::runtime_error e) { catch(std::runtime_error e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
wxMessageBox( ToUnicode(e.what()), wxT("Not a Mega-Glest projectile particle XML file, or broken"), wxICON_ERROR); wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest projectile particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
} }
timer->Start(100); timer->Start(100);
} }
@@ -718,27 +776,46 @@ void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSp
} }
catch(std::runtime_error e) { catch(std::runtime_error e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
wxMessageBox( ToUnicode(e.what()), wxT("Not a Mega-Glest splash particle XML file, or broken"), wxICON_ERROR); wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest projectile particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
} }
timer->Start(100); timer->Start(100);
} }
void MainWindow::onMenuModeNormals(wxCommandEvent &event){ void MainWindow::onMenuModeNormals(wxCommandEvent &event){
try {
renderer->toggleNormals(); renderer->toggleNormals();
menuMode->Check(miModeNormals, renderer->getNormals()); menuMode->Check(miModeNormals, renderer->getNormals());
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuModeWireframe(wxCommandEvent &event){ void MainWindow::onMenuModeWireframe(wxCommandEvent &event){
try {
renderer->toggleWireframe(); renderer->toggleWireframe();
menuMode->Check(miModeWireframe, renderer->getWireframe()); menuMode->Check(miModeWireframe, renderer->getWireframe());
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuModeGrid(wxCommandEvent &event){ void MainWindow::onMenuModeGrid(wxCommandEvent &event){
try {
renderer->toggleGrid(); renderer->toggleGrid();
menuMode->Check(miModeGrid, renderer->getGrid()); menuMode->Check(miModeGrid, renderer->getGrid());
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuSpeedSlower(wxCommandEvent &event){ void MainWindow::onMenuSpeedSlower(wxCommandEvent &event){
try {
speed /= 1.5f; speed /= 1.5f;
if(speed < 0) { if(speed < 0) {
speed = 0; speed = 0;
@@ -747,8 +824,14 @@ void MainWindow::onMenuSpeedSlower(wxCommandEvent &event){
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0); string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuSpeedFaster(wxCommandEvent &event){ void MainWindow::onMenuSpeedFaster(wxCommandEvent &event){
try {
speed *= 1.5f; speed *= 1.5f;
if(speed > 1) { if(speed > 1) {
speed = 1; speed = 1;
@@ -757,9 +840,15 @@ void MainWindow::onMenuSpeedFaster(wxCommandEvent &event){
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0 ); string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0 );
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
// set menu checkboxes to what player color is used // set menu checkboxes to what player color is used
void MainWindow::onMenuColorRed(wxCommandEvent &event) { void MainWindow::onMenuColorRed(wxCommandEvent &event) {
try {
playerColor= Renderer::pcRed; playerColor= Renderer::pcRed;
menuCustomColor->Check(miColorRed, true); menuCustomColor->Check(miColorRed, true);
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorBlue, false);
@@ -770,8 +859,14 @@ void MainWindow::onMenuColorRed(wxCommandEvent &event){
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorMagenta, false);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorBlue(wxCommandEvent &event) { void MainWindow::onMenuColorBlue(wxCommandEvent &event) {
try {
playerColor= Renderer::pcBlue; playerColor= Renderer::pcBlue;
menuCustomColor->Check(miColorRed, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, true); menuCustomColor->Check(miColorBlue, true);
@@ -782,8 +877,14 @@ void MainWindow::onMenuColorBlue(wxCommandEvent &event){
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorMagenta, false);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorGreen(wxCommandEvent &event) { void MainWindow::onMenuColorGreen(wxCommandEvent &event) {
try {
playerColor= Renderer::pcGreen; playerColor= Renderer::pcGreen;
menuCustomColor->Check(miColorRed, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorBlue, false);
@@ -794,8 +895,14 @@ void MainWindow::onMenuColorGreen(wxCommandEvent &event){
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorMagenta, false);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorYellow(wxCommandEvent &event) { void MainWindow::onMenuColorYellow(wxCommandEvent &event) {
try {
playerColor= Renderer::pcYellow; playerColor= Renderer::pcYellow;
menuCustomColor->Check(miColorRed, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorBlue, false);
@@ -806,8 +913,14 @@ void MainWindow::onMenuColorYellow(wxCommandEvent &event){
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorMagenta, false);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorWhite(wxCommandEvent &event) { void MainWindow::onMenuColorWhite(wxCommandEvent &event) {
try {
playerColor= Renderer::pcWhite; playerColor= Renderer::pcWhite;
menuCustomColor->Check(miColorRed, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorBlue, false);
@@ -818,8 +931,14 @@ void MainWindow::onMenuColorWhite(wxCommandEvent &event){
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorMagenta, false);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorCyan(wxCommandEvent &event) { void MainWindow::onMenuColorCyan(wxCommandEvent &event) {
try {
playerColor= Renderer::pcCyan; playerColor= Renderer::pcCyan;
menuCustomColor->Check(miColorRed, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorBlue, false);
@@ -830,8 +949,14 @@ void MainWindow::onMenuColorCyan(wxCommandEvent &event){
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorMagenta, false);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorOrange(wxCommandEvent &event) { void MainWindow::onMenuColorOrange(wxCommandEvent &event) {
try {
playerColor= Renderer::pcOrange; playerColor= Renderer::pcOrange;
menuCustomColor->Check(miColorRed, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorBlue, false);
@@ -842,8 +967,14 @@ void MainWindow::onMenuColorOrange(wxCommandEvent &event){
menuCustomColor->Check(miColorOrange, true); menuCustomColor->Check(miColorOrange, true);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorMagenta, false);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorMagenta(wxCommandEvent &event) { void MainWindow::onMenuColorMagenta(wxCommandEvent &event) {
try {
playerColor= Renderer::pcMagenta; playerColor= Renderer::pcMagenta;
menuCustomColor->Check(miColorRed, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorBlue, false);
@@ -854,6 +985,11 @@ void MainWindow::onMenuColorMagenta(wxCommandEvent &event){
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, true); menuCustomColor->Check(miColorMagenta, true);
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onTimer(wxTimerEvent &event) { void MainWindow::onTimer(wxTimerEvent &event) {
@@ -881,6 +1017,7 @@ string MainWindow::getModelInfo(){
void MainWindow::onKeyDown(wxKeyEvent &e) { void MainWindow::onKeyDown(wxKeyEvent &e) {
try {
// std::cout << "e.ControlDown() = " << e.ControlDown() << " e.GetKeyCode() = " << e.GetKeyCode() << " isCtrl = " << (e.GetKeyCode() == WXK_CONTROL) << std::endl; // std::cout << "e.ControlDown() = " << e.ControlDown() << " e.GetKeyCode() = " << e.GetKeyCode() << " isCtrl = " << (e.GetKeyCode() == WXK_CONTROL) << std::endl;
// Note: This ctrl-key handling is buggy since it never resests when ctrl is released later, so I reset it at end of loadcommands for now. // Note: This ctrl-key handling is buggy since it never resests when ctrl is released later, so I reset it at end of loadcommands for now.
@@ -946,8 +1083,14 @@ void MainWindow::onKeyDown(wxKeyEvent &e) {
glLightfv(GL_LIGHT0,GL_AMBIENT, ambientNEW.ptr()); glLightfv(GL_LIGHT0,GL_AMBIENT, ambientNEW.ptr());
} }
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuRestart(wxCommandEvent &event) { void MainWindow::onMenuRestart(wxCommandEvent &event) {
try {
// std::cout << "pressed R (restart particle animation)" << std::endl; // std::cout << "pressed R (restart particle animation)" << std::endl;
renderer->end(); renderer->end();
@@ -966,6 +1109,11 @@ void MainWindow::onMenuRestart(wxCommandEvent &event){
renderer->initModelManager(); renderer->initModelManager();
renderer->initTextureManager(); renderer->initTextureManager();
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
BEGIN_EVENT_TABLE(MainWindow, wxFrame) BEGIN_EVENT_TABLE(MainWindow, wxFrame)
EVT_TIMER(-1, MainWindow::onTimer) EVT_TIMER(-1, MainWindow::onTimer)