From 832d168be080c928ed57ad8de6feca2fc56caa1d Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 7 May 2009 06:05:43 +0000 Subject: [PATCH] fix a crash in matrix stack handling which was corrupting emulator state --- desmume/src/gfx3d.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index 2a1796370..e748cc2f1 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -418,8 +418,9 @@ void gfx3d_glStoreMatrix(u32 v) //this command always works on both pos and vector when either pos or pos-vector are the current mtx mode short mymode = (mode==1?2:mode); - //for the projection matrix, the provided value is supposed to be reset to zero - if(mymode==0) + //limit height of these stacks. + //without the mymode==3 namco classics galaxian will try to use pos=1 and overrun the stack, corrupting emu + if(mymode==0 || mymode==3) v = 0; if(v==31) v=30; //? what should happen in this case? @@ -434,8 +435,9 @@ void gfx3d_glRestoreMatrix(u32 v) //this command always works on both pos and vector when either pos or pos-vector are the current mtx mode short mymode = (mode==1?2:mode); - //for the projection matrix, the provided value is supposed to be reset to zero - if(mymode==0) + //limit height of these stacks + //without the mymode==3 namco classics galaxian will try to use pos=1 and overrun the stack, corrupting emu + if(mymode==0 || mymode==3) v = 0; if(v==31) v=30; //? what should happen in this case?