Merge pull request #163 from WaywardHeart/hang-on-close

Don't hang if the user closes the game while it's still initializing
This commit is contained in:
Splendide Imaginarius 2024-04-29 20:53:00 +00:00 committed by GitHub
commit b42c13a8ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 2 deletions

View file

@ -531,7 +531,7 @@ RB_METHOD(mkxpSystemMemory) {
RB_METHOD(mkxpReloadPathCache) {
RB_UNUSED_PARAM;
shState->fileSystem().reloadPathCache();
GUARD_EXC(shState->fileSystem().reloadPathCache(););
return Qnil;
}
@ -968,7 +968,11 @@ static void runRMXPScripts(BacktraceData &btData) {
/* Execute preloaded scripts */
for (std::vector<std::string>::const_iterator i = conf.preloadScripts.begin();
i != conf.preloadScripts.end(); ++i)
{
if (shState->rtData().rqTerm)
break;
runCustomScript(*i);
}
VALUE exc = rb_gv_get("$!");
if (exc != Qnil)
@ -976,6 +980,9 @@ static void runRMXPScripts(BacktraceData &btData) {
while (true) {
for (long i = 0; i < scriptCount; ++i) {
if (shState->rtData().rqTerm)
break;
VALUE script = rb_ary_entry(scriptArray, i);
VALUE scriptDecoded = rb_ary_entry(script, 3);
VALUE string =

View file

@ -396,6 +396,9 @@ struct CacheEnumData {
static PHYSFS_EnumerateCallbackResult cacheEnumCB(void *d, const char *origdir,
const char *fname) {
if (shState && shState->rtData().rqTerm)
throw Exception(Exception::MKXPError, "Game close requested. Aborting path cache enumeration.");
CacheEnumData &data = *static_cast<CacheEnumData *>(d);
char fullPath[512];

View file

@ -115,6 +115,9 @@ struct SharedStatePrivate
_glState(threadData->config),
fontState(threadData->config),
stampCounter(0)
{}
void init(RGSSThreadData *threadData)
{
startupTime = std::chrono::steady_clock::now();
@ -380,7 +383,24 @@ unsigned int SharedState::genTimeStamp()
SharedState::SharedState(RGSSThreadData *threadData)
{
p = new SharedStatePrivate(threadData);
SharedState::instance = this;
try
{
p->init(threadData);
p->screen = p->graphics.getScreen();
}
catch (const Exception &exc)
{
// If the "error" was the user quitting the game before the path cache finished building,
// then just return
if (rtData().rqTerm)
return;
delete p;
SharedState::instance = 0;
throw exc;
}
}
SharedState::~SharedState()