From d62d4bb90050ee195ef10996bd702b770c519eb1 Mon Sep 17 00:00:00 2001 From: Dave Demers <56704919+Producks@users.noreply.github.com> Date: Sat, 19 Jul 2025 18:59:21 -0400 Subject: [PATCH] Fix #400 and divide by zero (#454) * Divide by zero fix & cup restart behavior fix * CI Test * Fix a divide by zero bug. Fix for cups when using the reset button * Added defines, renamed function --------- Co-authored-by: MegaMech --- src/menus.c | 6 ++++-- src/menus.h | 6 +++++- src/port/Game.cpp | 14 +++++++++----- src/port/Game.h | 2 ++ src/port/ui/Menu.h | 4 ++++ src/port/ui/ResolutionEditor.cpp | 2 +- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/menus.c b/src/menus.c index 78bdadcfc..cfc6394be 100644 --- a/src/menus.c +++ b/src/menus.c @@ -66,12 +66,14 @@ s8 gCharacterSelections[4] = { MARIO, LUIGI, YOSHI, TOAD }; // The current row selected in the mode column for each player indexed // 0-1 1p / 0-2 2p´/ 0-1 3p / 0-1 4p -s8 gGameModeMenuColumn[4] = { 0, 0, 0, 0 }; +s8 gGameModeMenuColumn[NUM_ROWS_GAME_MODE_MENU] = { 0, 0, 0, 0 }; // For Grand Prix and Versus, this will be the CC mode selected. For Time Trials, it will // be whether 'Begin' or 'Data' is selected. Not used for Battle. // indexed as [column][row] -s8 gGameModeSubMenuColumn[4][3] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; +s8 gGameModeSubMenuColumn[NUM_COLUMN_GAME_MODE_SUB_MENU][NUM_ROWS_GAME_MODE_SUB_MENU] = { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } +}; s8 gNextDemoId = 0; s8 gControllerPakSelectedTableRow = 0; // 0-4 index, value of the current visible row select diff --git a/src/menus.h b/src/menus.h index 534b104a9..7a64c3009 100644 --- a/src/menus.h +++ b/src/menus.h @@ -190,6 +190,10 @@ enum ControllerPakScrollDirectionTypes { CONTROLLER_PAK_SCROLL_DIR_UP }; +#define NUM_ROWS_GAME_MODE_MENU 4 +#define NUM_COLUMN_GAME_MODE_SUB_MENU 4 +#define NUM_ROWS_GAME_MODE_SUB_MENU 3 + // This really, really shouldn't be in this header file, but I don't know where else to put it void rmonPrintf(const char*, ...); @@ -254,7 +258,7 @@ extern s32 gFadeModeSelection; extern s8 gCharacterSelections[]; extern s8 gGameModeMenuColumn[]; -extern s8 gGameModeSubMenuColumn[4][3]; +extern s8 gGameModeSubMenuColumn[NUM_COLUMN_GAME_MODE_SUB_MENU][NUM_ROWS_GAME_MODE_SUB_MENU]; extern s8 gNextDemoId; extern s8 gControllerPakSelectedTableRow; extern s8 gControllerPakVisibleTableRows[]; diff --git a/src/port/Game.cpp b/src/port/Game.cpp index 7e93888e7..068651bff 100644 --- a/src/port/Game.cpp +++ b/src/port/Game.cpp @@ -144,12 +144,8 @@ void CustomEngineInit() { gWorldInstance.AddCup(gSpecialCup); gWorldInstance.AddCup(gBattleCup); - /* Set default course; mario raceway */ //SelectMarioRaceway(); // This results in a nullptr - gWorldInstance.CurrentCourse = mario; - gWorldInstance.CurrentCup = gMushroomCup; - gWorldInstance.CurrentCup->CursorPosition = 3; - gWorldInstance.CupIndex = 0; + SetMarioRaceway(); // ModelLoader::LoadModelList bowserStatueList = { // .course = gBowsersCastle, @@ -198,6 +194,14 @@ void CM_SpawnFromLevelProps() { // Editor::SpawnFromLevelProps(); } +// Set default course; mario raceway +void SetMarioRaceway(void) { + SetCourseById(0); + gWorldInstance.CurrentCup = gMushroomCup; + gWorldInstance.CurrentCup->CursorPosition = 3; + gWorldInstance.CupIndex = 0; +} + World* GetWorld(void) { return &gWorldInstance; } diff --git a/src/port/Game.h b/src/port/Game.h index 3cc63afc0..ad4f61ca4 100644 --- a/src/port/Game.h +++ b/src/port/Game.h @@ -131,6 +131,8 @@ void CM_TickActors(); void CM_DrawBombKarts(s32 cameraId); +void SetMarioRaceway(void); + size_t GetCupCursorPosition(); void SetCupCursorPosition(size_t position); diff --git a/src/port/ui/Menu.h b/src/port/ui/Menu.h index 6efd056ca..bfa7e68a8 100644 --- a/src/port/ui/Menu.h +++ b/src/port/ui/Menu.h @@ -4,6 +4,7 @@ #include #include "UIWidgets.h" #include "MenuTypes.h" +#include "../port/Game.h" extern "C" { #include "defines.h" @@ -60,6 +61,9 @@ class Menu : public GuiWindow { virtual void ProcessReset() { gGamestateNext = MAIN_MENU_FROM_QUIT; gIsGamePaused = 0; + SetMarioRaceway(); + memset(&gGameModeMenuColumn, 0, sizeof(s8) * NUM_ROWS_GAME_MODE_MENU); + memset(&gGameModeSubMenuColumn, 0, sizeof(s8) * NUM_COLUMN_GAME_MODE_SUB_MENU * NUM_ROWS_GAME_MODE_SUB_MENU); switch(CVarGetInteger("gSkipIntro", 0)) { case 0: diff --git a/src/port/ui/ResolutionEditor.cpp b/src/port/ui/ResolutionEditor.cpp index ca47cb15e..d3d894c58 100644 --- a/src/port/ui/ResolutionEditor.cpp +++ b/src/port/ui/ResolutionEditor.cpp @@ -508,7 +508,7 @@ void UpdateResolutionVars() { ((float)gfx_current_dimensions.width / gfx_current_dimensions.height)) { // Scale to window height integerScale_maximumBounds = gfx_current_game_window_viewport.height / gfx_current_game_window_viewport.height; - } else { + } else if (gfx_current_game_window_viewport.width) { // Scale to window width integerScale_maximumBounds = gfx_current_game_window_viewport.width / gfx_current_game_window_viewport.width; }