| 42 | |
| 43 | template<class AppClass> |
| 44 | int startApp() |
| 45 | { |
| 46 | try |
| 47 | { |
| 48 | #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 |
| 49 | // set working directory to exe location |
| 50 | LPSTR fileName = new CHAR[256]; |
| 51 | GetModuleFileName(nullptr, fileName, 256); |
| 52 | std::string_view path = fileName; |
| 53 | size_t path_directory_index = path.find_last_of('\\'); |
| 54 | std::string exedir{path.substr(0, path_directory_index + 1)}; |
| 55 | _chdir(exedir.c_str()); |
| 56 | #endif |
| 57 | |
| 58 | AppClass* app = new AppClass(); |
| 59 | app->prepare(); |
| 60 | if (app->create()) |
| 61 | { |
| 62 | #ifdef EMSCRIPTEN |
| 63 | emscripten_set_main_loop_arg(run<AppClass>, app, 120, true); |
| 64 | #else |
| 65 | app->run(); |
| 66 | #endif |
| 67 | app->destroy(); |
| 68 | } |
| 69 | delete app; |
| 70 | app = nullptr; |
| 71 | } |
| 72 | catch (MyGUI::Exception& _e) |
| 73 | { |
| 74 | #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 |
| 75 | MessageBoxA( |
| 76 | nullptr, |
| 77 | _e.getFullDescription().c_str(), |
| 78 | "An exception has occured", |
| 79 | MB_OK | MB_ICONERROR | MB_TASKMODAL); |
| 80 | #else |
| 81 | std::cerr << "An exception has occured" |
| 82 | << " : " << _e.getFullDescription().c_str(); |
| 83 | #endif |
| 84 | throw; |
| 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | #endif |