fix Furnace not exiting after error during startup

This commit is contained in:
tildearrow 2022-12-21 01:20:56 -05:00
parent 019b036853
commit b208d2f32b

View file

@ -426,17 +426,20 @@ int main(int argc, char** argv) {
FILE* f=ps_fopen(fileName.c_str(),"rb");
if (f==NULL) {
reportError(fmt::sprintf("couldn't open file! (%s)",strerror(errno)));
finishLogFile();
return 1;
}
if (fseek(f,0,SEEK_END)<0) {
reportError(fmt::sprintf("couldn't open file! (couldn't get file size: %s)",strerror(errno)));
fclose(f);
finishLogFile();
return 1;
}
ssize_t len=ftell(f);
if (len==(SIZE_MAX>>1)) {
reportError(fmt::sprintf("couldn't open file! (couldn't get file length: %s)",strerror(errno)));
fclose(f);
finishLogFile();
return 1;
}
if (len<1) {
@ -446,6 +449,7 @@ int main(int argc, char** argv) {
reportError(fmt::sprintf("couldn't open file! (tell error: %s)",strerror(errno)));
}
fclose(f);
finishLogFile();
return 1;
}
unsigned char* file=new unsigned char[len];
@ -453,23 +457,27 @@ int main(int argc, char** argv) {
reportError(fmt::sprintf("couldn't open file! (size error: %s)",strerror(errno)));
fclose(f);
delete[] file;
finishLogFile();
return 1;
}
if (fread(file,1,(size_t)len,f)!=(size_t)len) {
reportError(fmt::sprintf("couldn't open file! (read error: %s)",strerror(errno)));
fclose(f);
delete[] file;
finishLogFile();
return 1;
}
fclose(f);
if (!e.load(file,(size_t)len)) {
reportError(fmt::sprintf("could not open file! (%s)",e.getLastError()));
finishLogFile();
return 1;
}
}
if (!e.init()) {
if (consoleMode) {
reportError("could not initialize engine!");
finishLogFile();
return 1;
} else {
logE("could not initialize engine!");
@ -483,6 +491,7 @@ int main(int argc, char** argv) {
} else {
e.benchmarkPlayback();
}
finishLogFile();
return 0;
}
if (outName!="" || vgmOutName!="" || cmdOutName!="") {
@ -523,6 +532,7 @@ int main(int argc, char** argv) {
e.saveAudio(outName.c_str(),loops,outMode);
e.waitAudioFile();
}
finishLogFile();
return 0;
}
@ -540,6 +550,7 @@ int main(int argc, char** argv) {
cli.loop();
cli.finish();
e.quit();
finishLogFile();
return 0;
} else {
#ifdef HAVE_SDL2
@ -549,6 +560,7 @@ int main(int argc, char** argv) {
if (ev.type==SDL_QUIT) break;
}
e.quit();
finishLogFile();
return 0;
#else
while (true) {
@ -566,6 +578,7 @@ int main(int argc, char** argv) {
g.bindEngine(&e);
if (!g.init()) {
reportError(g.getLastError());
finishLogFile();
return 1;
}