From 5ba00edf20806613a4532f2c009f332a277b195f Mon Sep 17 00:00:00 2001 From: arthurtilly <32559225+arthurtilly@users.noreply.github.com> Date: Mon, 22 Jan 2024 07:38:00 +1300 Subject: [PATCH] Add assert for beginning geo layout command (#738) * geo layout assert * new idea * Change assert message, add crash screen newline support, and change debug safeguards --------- Co-authored-by: Gregory Heskett --- include/config/config_safeguards.h | 5 +++++ include/geo_commands.h | 2 ++ src/engine/geo_layout.c | 2 ++ src/game/crash_screen.c | 10 +++++++--- src/game/debug.h | 2 +- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/config/config_safeguards.h b/include/config/config_safeguards.h index 3ddc689b..3c7dce3f 100644 --- a/include/config/config_safeguards.h +++ b/include/config/config_safeguards.h @@ -132,6 +132,11 @@ #define UNLOCK_ALL #endif // COMPLETE_SAVE_FILE +#ifdef DEBUG + #undef DEBUG_ASSERTIONS + #define DEBUG_ASSERTIONS +#endif // DEBUG + /***************** * config_camera.h diff --git a/include/geo_commands.h b/include/geo_commands.h index d8c0c6e4..56706cc7 100644 --- a/include/geo_commands.h +++ b/include/geo_commands.h @@ -58,6 +58,8 @@ enum GeoLayoutCommands { /*0x1E*/ GEO_CMD_NOP_1E, /*0x1F*/ GEO_CMD_NOP_1F, /*0x20*/ GEO_CMD_NODE_CULLING_RADIUS, + + GEO_CMD_COUNT, }; // geo layout macros diff --git a/src/engine/geo_layout.c b/src/engine/geo_layout.c index d91dac3d..3d81a5e6 100644 --- a/src/engine/geo_layout.c +++ b/src/engine/geo_layout.c @@ -5,6 +5,7 @@ #include "math_util.h" #include "game/memory.h" #include "graph_node.h" +#include "game/debug.h" typedef void (*GeoLayoutCommandProc)(void); @@ -771,6 +772,7 @@ struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr) { gGeoLayoutStack[1] = 0; while (gGeoLayoutCommand != NULL) { + assert((gGeoLayoutCommand[0x00] < GEO_CMD_COUNT), "Invalid or unloaded geo layout detected."); GeoLayoutJumpTable[gGeoLayoutCommand[0x00]](); } diff --git a/src/game/crash_screen.c b/src/game/crash_screen.c index c716856d..6b199da9 100644 --- a/src/game/crash_screen.c +++ b/src/game/crash_screen.c @@ -133,6 +133,7 @@ void crash_screen_print(s32 x, s32 y, const char *fmt, ...) { char *ptr; u32 glyph; s32 size; + s32 xOffset = x; char buf[0x108]; bzero(&buf, sizeof(buf)); @@ -147,12 +148,15 @@ void crash_screen_print(s32 x, s32 y, const char *fmt, ...) { while (*ptr) { glyph = gCrashScreenCharToGlyph[*ptr & 0x7f]; - if (glyph != 0xff) { - crash_screen_draw_glyph(x, y, glyph); + if (*ptr == '\n') { + xOffset = x; + y += 10; + } else if (glyph != 0xff) { + crash_screen_draw_glyph(xOffset, y, glyph); } ptr++; - x += 6; + xOffset += 6; } } diff --git a/src/game/debug.h b/src/game/debug.h index c8862f13..9719007f 100644 --- a/src/game/debug.h +++ b/src/game/debug.h @@ -62,7 +62,7 @@ extern void __n64Assert(char *fileName, u32 lineNum, char *message); /** * Will cause a crash if cond is not true, and DEBUG is defined (allows for quick removal of littered asserts) */ -#if defined(DEBUG) || defined(DEBUG_ASSERTIONS) +#ifdef DEBUG_ASSERTIONS #define assert(cond, message) do {\ if ((cond) == FALSE) { \ error(message); \