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
1 changed files with 13 additions and 0 deletions

View File

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