From ff633d5acd33ff4ea326cdd1a6743cb663264d92 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 23 Aug 2022 22:01:11 -0400 Subject: [PATCH] add new function FCEU_abort() for calling abort() with a message; use it when memory allocation fails instead of exit() --- src/utils/memory.cpp | 11 +++++++---- src/utils/memory.h | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/utils/memory.cpp b/src/utils/memory.cpp index c261cbf3..93bc3af9 100644 --- a/src/utils/memory.cpp +++ b/src/utils/memory.cpp @@ -42,10 +42,7 @@ static void *_FCEU_malloc(uint32 size) #endif if(!ret) - { - FCEU_PrintError("Error allocating memory! Doing a hard exit."); - exit(1); - } + FCEU_abort("Error allocating memory!"); return ret; } @@ -98,3 +95,9 @@ void FCEU_dfree(void *ptr) { return FCEU_free(ptr); } + +void FCEU_abort(const char* message) +{ + if(message) FCEU_PrintError(message); + abort(); +} diff --git a/src/utils/memory.h b/src/utils/memory.h index 174b3d31..b9e6f145 100644 --- a/src/utils/memory.h +++ b/src/utils/memory.h @@ -42,3 +42,6 @@ void *FCEU_dmalloc(uint32 size); //don't use these. change them if you find them. void FCEU_dfree(void *ptr); + +//aborts the process for fatal errors +void FCEU_abort(const char* message = nullptr);