Stop main menu and CSM formspec input errors from crashing the game entirely on Android

master
luk3yx 2022-05-30 19:44:52 +12:00
parent 2d0b2e7ea7
commit 4765019103
3 changed files with 32 additions and 8 deletions

View File

@ -195,8 +195,18 @@ struct LocalFormspecHandler : public TextDest
return;
}
if (m_client->modsLoaded())
m_client->getScript()->on_formspec_input(m_formname, fields);
if (m_client->modsLoaded()) {
try {
m_client->getScript()->on_formspec_input(m_formname, fields);
} catch (LuaError &e) {
const std::string error_message = std::string("LuaError: ") + e.what() +
strgettext("\nCheck debug.txt for details.");
m_client->setFatalError(error_message);
#ifdef __ANDROID__
porting::handleError("LuaError (on_formspec_input)", error_message);
#endif
}
}
}
Client *m_client = nullptr;

View File

@ -48,7 +48,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
/******************************************************************************/
void TextDestGuiEngine::gotText(const StringMap &fields)
{
m_engine->getScriptIface()->handleMainMenuButtons(fields);
try {
m_engine->getScriptIface()->handleMainMenuButtons(fields);
} catch (LuaError &e) {
m_engine->handleMainMenuLuaError(e.what());
}
}
/******************************************************************************/
@ -199,11 +203,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
run();
} catch (LuaError &e) {
errorstream << "Main menu error: " << e.what() << std::endl;
m_data->script_data.errormessage = e.what();
#ifdef __ANDROID__
porting::handleError("Main menu error", e.what());
#endif
handleMainMenuLuaError(e.what());
}
m_menu->quitMenu();
@ -211,6 +211,18 @@ GUIEngine::GUIEngine(JoystickController *joystick,
m_menu = NULL;
}
void GUIEngine::handleMainMenuLuaError(const char* errmsg) {
errorstream << "Main menu error: " << errmsg << std::endl;
m_data->script_data.errormessage = errmsg;
#ifdef __ANDROID__
porting::handleError("Main menu error", errmsg);
#endif
// Make the menu quit. Since an error message has been set this won't
// actually start the game.
m_startgame = true;
}
/******************************************************************************/
bool GUIEngine::loadMainMenuScript()
{

View File

@ -157,6 +157,8 @@ public:
/** default destructor */
virtual ~GUIEngine();
void handleMainMenuLuaError(const char* errmsg);
/**
* return MainMenuScripting interface
*/