Skip to content

Commit

Permalink
Merge pull request Ancurio#163 from WaywardHeart/hang-on-close
Browse files Browse the repository at this point in the history
Don't hang if the user closes the game while it's still initializing
  • Loading branch information
Splendide-Imaginarius authored Apr 29, 2024
2 parents 89801da + 9e8132b commit b42c13a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion binding/binding-mri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ RB_METHOD(mkxpSystemMemory) {
RB_METHOD(mkxpReloadPathCache) {
RB_UNUSED_PARAM;

shState->fileSystem().reloadPathCache();
GUARD_EXC(shState->fileSystem().reloadPathCache(););
return Qnil;
}

Expand Down Expand Up @@ -968,14 +968,21 @@ 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)
return;

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 =
Expand Down
3 changes: 3 additions & 0 deletions src/filesystem/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
22 changes: 21 additions & 1 deletion src/sharedstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ struct SharedStatePrivate
_glState(threadData->config),
fontState(threadData->config),
stampCounter(0)
{}

void init(RGSSThreadData *threadData)
{

startupTime = std::chrono::steady_clock::now();
Expand Down Expand Up @@ -380,7 +383,24 @@ unsigned int SharedState::genTimeStamp()
SharedState::SharedState(RGSSThreadData *threadData)
{
p = new SharedStatePrivate(threadData);
p->screen = p->graphics.getScreen();
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()
Expand Down

0 comments on commit b42c13a

Please sign in to comment.