1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Fix crash on closing vcmi while opening is playing

This commit is contained in:
Ivan Savenko
2023-12-20 14:18:53 +02:00
parent a507acea59
commit ee976d676d

View File

@@ -55,12 +55,14 @@
namespace po = boost::program_options; namespace po = boost::program_options;
namespace po_style = boost::program_options::command_line_style; namespace po_style = boost::program_options::command_line_style;
static std::atomic<bool> quitRequestedDuringOpeningPlayback = false;
static po::variables_map vm; static po::variables_map vm;
#ifndef VCMI_IOS #ifndef VCMI_IOS
void processCommand(const std::string &message); void processCommand(const std::string &message);
#endif #endif
void playIntro(); void playIntro();
[[noreturn]] static void quitApplication();
static void mainLoop(); static void mainLoop();
static CBasicLogConfigurator *logConfig; static CBasicLogConfigurator *logConfig;
@@ -313,7 +315,6 @@ int main(int argc, char * argv[])
GH.screenHandler().clearScreen(); GH.screenHandler().clearScreen();
} }
#ifndef VCMI_NO_THREADED_LOAD #ifndef VCMI_NO_THREADED_LOAD
#ifdef VCMI_ANDROID // android loads the data quite slowly so we display native progressbar to prevent having only black screen for few seconds #ifdef VCMI_ANDROID // android loads the data quite slowly so we display native progressbar to prevent having only black screen for few seconds
{ {
@@ -327,6 +328,9 @@ int main(int argc, char * argv[])
#endif // ANDROID #endif // ANDROID
#endif // THREADED #endif // THREADED
if (quitRequestedDuringOpeningPlayback)
quitApplication();
if(!settings["session"]["headless"].Bool()) if(!settings["session"]["headless"].Bool())
{ {
pomtime.getDiff(); pomtime.getDiff();
@@ -451,7 +455,7 @@ static void mainLoop()
} }
} }
static void quitApplication() [[noreturn]] static void quitApplication()
{ {
if(!settings["session"]["headless"].Bool()) if(!settings["session"]["headless"].Bool())
{ {
@@ -516,6 +520,15 @@ static void quitApplication()
void handleQuit(bool ask) void handleQuit(bool ask)
{ {
// FIXME: avoids crash if player attempts to close game while opening is still playing
// use cursor handler as indicator that loading is not done yet
// proper solution would be to abort init thread (or wait for it to finish)
if (!CCS->curh)
{
quitRequestedDuringOpeningPlayback = true;
return;
}
if(ask) if(ask)
{ {
CCS->curh->set(Cursor::Map::POINTER); CCS->curh->set(Cursor::Map::POINTER);