From 828c9329a3edd5bc6675f79d63b000d500ca0a13 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Fri, 17 Sep 2021 07:43:19 +0200 Subject: [PATCH] Add detailed Z_Malloc error messages --- cgdoom/cgdoom-ui.c | 21 +++++++++++++++++++++ cgdoom/os.h | 2 -- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cgdoom/cgdoom-ui.c b/cgdoom/cgdoom-ui.c index 38bf8dd..cb78d81 100644 --- a/cgdoom/cgdoom-ui.c +++ b/cgdoom/cgdoom-ui.c @@ -1,4 +1,6 @@ #include "cgdoom-ui.h" +#include "i_system.h" +#include "z_zone.h" #include #include @@ -479,6 +481,25 @@ void UI_Error(const char *fmt, va_list args) while(*str && isspace_(*str)) str++; } + /* Additional info for heap errors */ + if(!strncmp(fmt, "Z_", 2)) { + y += 12; + + UI_Print(LAYOUT_LEFT, y, 0x0000, UI_LEFT, "Free memory in heap:", -1); + y += 14; + + for (int i = 0;; i++) { + int size; + byte *ptr = I_ZoneBase(&size, i); + if (!ptr) break; + + UI_Printf(LAYOUT_LEFT, y, 0x0000, UI_LEFT, + "Zone #%d: %d/%d kB (largest block %d B)", + i, Z_FreeMemory(i) >> 10, size >> 10, Z_LargestFreeBlock(i)); + y += 14; + } + } + Bdisp_FrameAndColor(3, 16); Bdisp_FrameAndColor(1, 0); Bdisp_PutDisp_DD(); diff --git a/cgdoom/os.h b/cgdoom/os.h index ebf1688..2c0f213 100644 --- a/cgdoom/os.h +++ b/cgdoom/os.h @@ -35,8 +35,6 @@ void I_Error (const char *error, ...); //force compiler error on use following: #define strcpy 12 #define strnicmp 22 -#define strncmp 27 -#define strcmp 33 //return ptr to flash int FindInFlash(const void **buf, int size, int readpos);