- 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
void MainWindow::onMouseWheelDown(wxMouseEvent &event) {
try {
wxPaintEvent paintEvent;
zoom*= 1.1f;
zoom= clamp(zoom, 0.1f, 10.0f);
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) {
try {
wxPaintEvent paintEvent;
zoom*= 0.90909f;
zoom= clamp(zoom, 0.1f, 10.0f);
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){
try {
int x= event.GetX();
int y= event.GetY();
wxPaintEvent paintEvent;
@ -257,9 +270,15 @@ void MainWindow::onMouseMove(wxMouseEvent &event){
lastX= x;
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) {
try {
//wxColour color = colorPicker->GetColour();
wxColourData data;
data.SetChooseFull(true);
@ -281,13 +300,17 @@ void MainWindow::OnChangeColor(wxCommandEvent &event) {
//myWindow->Clear();
//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){
try {
string fileName;
fileDialog->SetWildcard(wxT("G3D files (*.g3d)|*.g3d"));
fileDialog->SetMessage(wxT("Selecting Glest Model for current view."));
if(fileDialog->ShowModal()==wxID_OK){
@ -295,9 +318,15 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event){
loadModel((const char*)wxFNCONV(fileDialog->GetPath().c_str()));
}
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){
try {
string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
@ -313,9 +342,15 @@ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
loadParticle(path);
}
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){
try {
string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
@ -331,9 +366,15 @@ void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){
loadProjectileParticle(path);
}
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){
try {
string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
@ -349,10 +390,16 @@ void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){
loadSplashParticle(path);
}
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?
void MainWindow::onMenuFileSaveScreenshot(wxCommandEvent &event) {
try {
string path = "screens/";
if(isdir(path.c_str()) == true) {
//Config &config= Config::getInstance();
@ -372,9 +419,15 @@ 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) {
try {
modelPathList.clear();
particlePathList.clear();
particleProjectilePathList.clear();
@ -402,6 +455,11 @@ void MainWindow::onMenuFileClearAll(wxCommandEvent &event) {
GetStatusBar()->SetStatusText(ToUnicode(statusbarText.c_str()));
timer->Start(100);
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) {
@ -513,7 +571,7 @@ void MainWindow::loadParticle(string path) {
}
catch(std::runtime_error e) {
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);
}
@ -619,7 +677,7 @@ void MainWindow::loadProjectileParticle(string path) {
}
catch(std::runtime_error e) {
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);
}
@ -718,27 +776,46 @@ void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSp
}
catch(std::runtime_error e) {
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);
}
void MainWindow::onMenuModeNormals(wxCommandEvent &event){
try {
renderer->toggleNormals();
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){
try {
renderer->toggleWireframe();
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){
try {
renderer->toggleGrid();
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){
try {
speed /= 1.5f;
if(speed < 0) {
speed = 0;
@ -746,9 +823,15 @@ void MainWindow::onMenuSpeedSlower(wxCommandEvent &event){
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0);
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){
try {
speed *= 1.5f;
if(speed > 1) {
speed = 1;
@ -756,10 +839,16 @@ void MainWindow::onMenuSpeedFaster(wxCommandEvent &event){
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0 );
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
void MainWindow::onMenuColorRed(wxCommandEvent &event){
void MainWindow::onMenuColorRed(wxCommandEvent &event) {
try {
playerColor= Renderer::pcRed;
menuCustomColor->Check(miColorRed, true);
menuCustomColor->Check(miColorBlue, false);
@ -769,9 +858,15 @@ void MainWindow::onMenuColorRed(wxCommandEvent &event){
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, 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;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, true);
@ -781,9 +876,15 @@ void MainWindow::onMenuColorBlue(wxCommandEvent &event){
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, 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;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
@ -793,9 +894,15 @@ void MainWindow::onMenuColorGreen(wxCommandEvent &event){
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, 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;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
@ -805,9 +912,15 @@ void MainWindow::onMenuColorYellow(wxCommandEvent &event){
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, 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;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
@ -817,9 +930,15 @@ void MainWindow::onMenuColorWhite(wxCommandEvent &event){
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, 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;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
@ -829,9 +948,15 @@ void MainWindow::onMenuColorCyan(wxCommandEvent &event){
menuCustomColor->Check(miColorCyan, true);
menuCustomColor->Check(miColorOrange, 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;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
@ -841,9 +966,15 @@ void MainWindow::onMenuColorOrange(wxCommandEvent &event){
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, true);
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;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
@ -853,10 +984,15 @@ void MainWindow::onMenuColorMagenta(wxCommandEvent &event){
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, false);
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) {
wxPaintEvent paintEvent;
anim = anim + speed;
@ -866,7 +1002,7 @@ void MainWindow::onTimer(wxTimerEvent &event){
onPaint(paintEvent);
}
string MainWindow::getModelInfo(){
string MainWindow::getModelInfo() {
string str;
if(model!=NULL){
@ -881,6 +1017,7 @@ string MainWindow::getModelInfo(){
void MainWindow::onKeyDown(wxKeyEvent &e) {
try {
// 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.
@ -945,9 +1082,15 @@ void MainWindow::onKeyDown(wxKeyEvent &e) {
Vec4f ambientNEW= Vec4f(lightBrightness, lightBrightness, lightBrightness, 1.0f);
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;
renderer->end();
@ -965,6 +1108,11 @@ void MainWindow::onMenuRestart(wxCommandEvent &event){
renderer->initModelManager();
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)