summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2025-01-24 19:47:37 -0700
committerGitHub <noreply@github.com>2025-01-24 19:47:37 -0700
commit73ba320831997d38b4d6431df3805c62b76400e7 (patch)
tree49c3f3da3dacd71f3de8078ef0f50b64b35eccbc /src
parent23133b6fc058d87d999ddcebc4dd4388f29b96c8 (diff)
Fix matrix stack heap corruption (#166)
* Fix matrix stack heap corruption * Fix matrix overflow bug
Diffstat (limited to 'src')
-rw-r--r--src/engine/Matrix.cpp43
-rw-r--r--src/engine/Matrix.h2
-rw-r--r--src/menu_items.c24
-rw-r--r--src/os/osInitialize.c2
4 files changed, 37 insertions, 34 deletions
diff --git a/src/engine/Matrix.cpp b/src/engine/Matrix.cpp
index 7b8c3b1fb..354389db9 100644
--- a/src/engine/Matrix.cpp
+++ b/src/engine/Matrix.cpp
@@ -34,29 +34,30 @@ void AddMatrixFixed(std::vector<Mtx>& stack, s32 flags) {
}
// Used in func_80095BD0
-void SetTextMatrix(f32 arg1, f32 arg2, f32 arg3, f32 arg4) {
- Mat4 mtx;
- mtx[0][0] = arg3;
- mtx[0][1] = 0.0f;
- mtx[0][2] = 0.0f;
- mtx[0][3] = 0.0f;
- mtx[1][0] = 0.0f;
- mtx[1][1] = arg4;
- mtx[1][2] = 0.0f;
- mtx[1][3] = 0.0f;
- mtx[2][0] = 0.0f;
- mtx[2][1] = 0.0f;
- mtx[2][2] = 1.0f;
- mtx[2][3] = 0.0f;
- mtx[3][0] = arg1;
- mtx[3][1] = arg2;
- mtx[3][2] = 0.0f;
- mtx[3][3] = 1.0f;
-
- AddMatrix(gWorldInstance.Mtx.Effects, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
+Mtx* SetTextMatrix(f32 arg1, f32 arg2, f32 arg3, f32 arg4) {
+ Mat4 matrix;
+ matrix[0][0] = arg3;
+ matrix[0][1] = 0.0f;
+ matrix[0][2] = 0.0f;
+ matrix[0][3] = 0.0f;
+ matrix[1][0] = 0.0f;
+ matrix[1][1] = arg4;
+ matrix[1][2] = 0.0f;
+ matrix[1][3] = 0.0f;
+ matrix[2][0] = 0.0f;
+ matrix[2][1] = 0.0f;
+ matrix[2][2] = 1.0f;
+ matrix[2][3] = 0.0f;
+ matrix[3][0] = arg1;
+ matrix[3][1] = arg2;
+ matrix[3][2] = 0.0f;
+ matrix[3][3] = 1.0f;
+ Mtx* mtx = GetMatrix(gWorldInstance.Mtx.Effects);
+ guMtxF2L(matrix, mtx);
+
+ return mtx;
}
-
// API
extern "C" {
diff --git a/src/engine/Matrix.h b/src/engine/Matrix.h
index cff3f22ac..f72af76c4 100644
--- a/src/engine/Matrix.h
+++ b/src/engine/Matrix.h
@@ -14,7 +14,7 @@ void AddObjectMatrix(Mat4 mtx, s32 flags);
void AddEffectMatrix(Mat4 mtx, s32 flags);
void AddEffectMatrixOrtho(void);
void AddEffectMatrixFixed(s32 flags);
-void SetTextMatrix(f32 arg1, f32 arg2, f32 arg3, f32 arg4);
+Mtx* SetTextMatrix(f32 arg1, f32 arg2, f32 arg3, f32 arg4);
Mtx* GetEffectMatrix(void);
void ClearHudMatrixPool(void);
void ClearEffectsMatrixPool(void);
diff --git a/src/menu_items.c b/src/menu_items.c
index 68a602aa1..7ca284617 100644
--- a/src/menu_items.c
+++ b/src/menu_items.c
@@ -2732,8 +2732,9 @@ func_80095BD0_label1:
rmonPrintf("MAX effectcount(760) over!!!!(kawano)\n");
return displayListHead;
func_80095BD0_label2:
- func_80095AE0(&gGfxPool->mtxEffect[gMatrixEffectCount], arg2, arg3, arg6, arg7);
- gSPMatrix(displayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxEffect[gMatrixEffectCount++]),
+ //func_80095AE0(&gGfxPool->mtxEffect[gMatrixEffectCount], arg2, arg3, arg6, arg7);
+ Mtx* mtx = SetTextMatrix(arg2, arg3, arg6, arg7);
+ gSPMatrix(displayListHead++, mtx,
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gMKLoadTextureTile_4b(displayListHead++, arg1, G_IM_FMT_I, arg4, 0, 0, 0, arg4, arg5, 0, G_TX_NOMIRROR | G_TX_WRAP,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
@@ -8299,7 +8300,8 @@ void func_800A66A8(MenuItem* arg0, Unk_D_800E70A0* arg1) {
static float x2, y2, z2;
static float x1, y1, z1;
- mtx = GetEffectMatrix(); // &gGfxPool->mtxEffect[gMatrixEffectCount];
+ mtx = GetEffectMatrix();
+ mtx2 = GetEffectMatrix();
if (arg0->paramf > 1.5) {
arg0->paramf *= 0.95;
} else {
@@ -8321,14 +8323,14 @@ void func_800A66A8(MenuItem* arg0, Unk_D_800E70A0* arg1) {
// clang-format on
guScale(mtx, 1.2f, 1.2f, 1.2f);
- guRotate(mtx + 1, y2, 0.0f, 1.0f, 0.0f);
- guMtxCatL(mtx, mtx + 1, mtx);
- guRotate(mtx + 1, z2, 0.0f, 0.0f, 1.0f);
- guMtxCatL(mtx, mtx + 1, mtx);
- guRotate(mtx + 1, x2, 1.0f, 0.0f, 0.0f);
- guMtxCatL(mtx, mtx + 1, mtx);
- guTranslate(mtx + 1, arg1->column, arg1->row, 0.0f);
- guMtxCatL(mtx, mtx + 1, mtx);
+ guRotate(mtx2, y2, 0.0f, 1.0f, 0.0f);
+ guMtxCatL(mtx, mtx2, mtx);
+ guRotate(mtx2, z2, 0.0f, 0.0f, 1.0f);
+ guMtxCatL(mtx, mtx2, mtx);
+ guRotate(mtx2, x2, 1.0f, 0.0f, 0.0f);
+ guMtxCatL(mtx, mtx2, mtx);
+ guTranslate(mtx2, arg1->column, arg1->row, 0.0f);
+ guMtxCatL(mtx, mtx2, mtx);
// gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxEffect[gMatrixEffectCount++]),
// (G_MTX_NOPUSH | G_MTX_LOAD) | G_MTX_MODELVIEW);
AddEffectMatrixFixed(G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
diff --git a/src/os/osInitialize.c b/src/os/osInitialize.c
index 45d6c1b3d..32376df0e 100644
--- a/src/os/osInitialize.c
+++ b/src/os/osInitialize.c
@@ -57,7 +57,7 @@ void osInitialize(void) {
}
osClockRate = osClockRate * 3 / 4;
if (osResetType == RESET_TYPE_COLD_RESET) {
- // bzero(osAppNmiBuffer, sizeof(osAppNmiBuffer));
+ bzero(osAppNmiBuffer, sizeof(osAppNmiBuffer));
}
eu_sp30 = HW_REG(PI_STATUS_REG, u32);