- some basic error catching to avoid application crash when errors occur
This commit is contained in:
parent
685c338f97
commit
d32a52a072
|
@ -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;
|
||||
|
@ -258,8 +271,14 @@ 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);
|
||||
|
@ -282,12 +301,16 @@ void MainWindow::OnChangeColor(wxCommandEvent &event) {
|
|||
//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){
|
||||
|
@ -296,8 +319,14 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event){
|
|||
}
|
||||
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"));
|
||||
|
||||
|
@ -314,8 +343,14 @@ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
|
|||
}
|
||||
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"));
|
||||
|
||||
|
@ -332,8 +367,14 @@ void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){
|
|||
}
|
||||
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();
|
||||
|
@ -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) {
|
||||
try {
|
||||
modelPathList.clear();
|
||||
particlePathList.clear();
|
||||
particleProjectilePathList.clear();
|
||||
|
@ -403,6 +456,11 @@ void MainWindow::onMenuFileClearAll(wxCommandEvent &event) {
|
|||
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) {
|
||||
Close();
|
||||
|
@ -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;
|
||||
|
@ -747,8 +824,14 @@ 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;
|
||||
|
@ -757,9 +840,15 @@ 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) {
|
||||
try {
|
||||
playerColor= Renderer::pcRed;
|
||||
menuCustomColor->Check(miColorRed, true);
|
||||
menuCustomColor->Check(miColorBlue, false);
|
||||
|
@ -770,8 +859,14 @@ void MainWindow::onMenuColorRed(wxCommandEvent &event){
|
|||
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) {
|
||||
try {
|
||||
playerColor= Renderer::pcBlue;
|
||||
menuCustomColor->Check(miColorRed, false);
|
||||
menuCustomColor->Check(miColorBlue, true);
|
||||
|
@ -782,8 +877,14 @@ void MainWindow::onMenuColorBlue(wxCommandEvent &event){
|
|||
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) {
|
||||
try {
|
||||
playerColor= Renderer::pcGreen;
|
||||
menuCustomColor->Check(miColorRed, false);
|
||||
menuCustomColor->Check(miColorBlue, false);
|
||||
|
@ -794,8 +895,14 @@ void MainWindow::onMenuColorGreen(wxCommandEvent &event){
|
|||
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) {
|
||||
try {
|
||||
playerColor= Renderer::pcYellow;
|
||||
menuCustomColor->Check(miColorRed, false);
|
||||
menuCustomColor->Check(miColorBlue, false);
|
||||
|
@ -806,8 +913,14 @@ void MainWindow::onMenuColorYellow(wxCommandEvent &event){
|
|||
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) {
|
||||
try {
|
||||
playerColor= Renderer::pcWhite;
|
||||
menuCustomColor->Check(miColorRed, false);
|
||||
menuCustomColor->Check(miColorBlue, false);
|
||||
|
@ -818,8 +931,14 @@ void MainWindow::onMenuColorWhite(wxCommandEvent &event){
|
|||
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) {
|
||||
try {
|
||||
playerColor= Renderer::pcCyan;
|
||||
menuCustomColor->Check(miColorRed, false);
|
||||
menuCustomColor->Check(miColorBlue, false);
|
||||
|
@ -830,8 +949,14 @@ void MainWindow::onMenuColorCyan(wxCommandEvent &event){
|
|||
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) {
|
||||
try {
|
||||
playerColor= Renderer::pcOrange;
|
||||
menuCustomColor->Check(miColorRed, false);
|
||||
menuCustomColor->Check(miColorBlue, false);
|
||||
|
@ -842,8 +967,14 @@ void MainWindow::onMenuColorOrange(wxCommandEvent &event){
|
|||
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) {
|
||||
try {
|
||||
playerColor= Renderer::pcMagenta;
|
||||
menuCustomColor->Check(miColorRed, false);
|
||||
menuCustomColor->Check(miColorBlue, false);
|
||||
|
@ -854,6 +985,11 @@ void MainWindow::onMenuColorMagenta(wxCommandEvent &event){
|
|||
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) {
|
||||
|
@ -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.
|
||||
|
@ -946,8 +1083,14 @@ void MainWindow::onKeyDown(wxKeyEvent &e) {
|
|||
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) {
|
||||
try {
|
||||
// std::cout << "pressed R (restart particle animation)" << std::endl;
|
||||
renderer->end();
|
||||
|
||||
|
@ -966,6 +1109,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)
|
||||
EVT_TIMER(-1, MainWindow::onTimer)
|
||||
|
|
Loading…
Reference in New Issue
Block a user