diff --git a/CHANGES b/CHANGES index 8c6d992a1..6a33406ae 100644 --- a/CHANGES +++ b/CHANGES @@ -28,6 +28,7 @@ Bugfixes: - GBA BIOS: Fix BIOS prefetch after reset - GBA Memory: Fix alignment of open bus 8- and 16-bit loads - GBA Thread: Fix possible hang when loading an archive + - Perf: Fix crash when the GBA thread fails to start Misc: - GBA Audio: Change internal audio sample buffer from 32-bit to 16-bit samples - GBA Memory: Simplify memory API and use fixed bus width diff --git a/src/platform/perf-main.c b/src/platform/perf-main.c index 5fc3ab72a..3e4f63b3c 100644 --- a/src/platform/perf-main.c +++ b/src/platform/perf-main.c @@ -86,7 +86,11 @@ int main(int argc, char** argv) { GBAMapArgumentsToContext(&args, &context); GBAMapOptionsToContext(&opts, &context); - GBAThreadStart(&context); + int didStart = GBAThreadStart(&context); + + if (!didStart) { + goto cleanup; + } GBAGetGameCode(context.gba, gameCode); int frames = perfOpts.frames; @@ -102,12 +106,6 @@ int main(int argc, char** argv) { uint64_t duration = end - start; GBAThreadJoin(&context); - GBAConfigFreeOpts(&opts); - freeArguments(&args); - GBAConfigDeinit(&config); - free(context.debugger); - - free(renderer.outputBuffer); float scaledFrames = frames * 1000000.f; if (perfOpts.csv) { @@ -123,7 +121,14 @@ int main(int argc, char** argv) { printf("%u frames in %" PRIu64 " microseconds: %g fps (%gx)\n", frames, duration, scaledFrames / duration, scaledFrames / (duration * 60.f)); } - return GBAThreadHasCrashed(&context); +cleanup: + GBAConfigFreeOpts(&opts); + freeArguments(&args); + GBAConfigDeinit(&config); + free(context.debugger); + free(renderer.outputBuffer); + + return !didStart || GBAThreadHasCrashed(&context); } static void _GBAPerfRunloop(struct GBAThread* context, int* frames, bool quiet) {