From b54baa86c6f0b88c4cc27e39bb7779d9b03a9f4c Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 14 Apr 2009 05:35:49 +0000 Subject: [PATCH] eliminate emulator crashes and freakouts when rendering some totally messed up 3d stuff. is this masking a deeper issue? quite possibly, but the checks need to be done anyway. --- desmume/src/gfx3d.cpp | 15 ++++++++++++++- desmume/src/rasterize.cpp | 9 ++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index 7e7334fbc..ddf3f934c 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -966,7 +966,20 @@ void gfx3d_glNormal(u32 v) if(dsSpecular & 0x8000) { - shininessLevel = shininessTable[(int)(shininessLevel * 128)]; + int shininessIndex = (int)(shininessLevel * 128); + if(shininessIndex >= ARRAY_SIZE(shininessTable)) { + //we can't print this right now, because when a game triggers this it triggers it _A_LOT_ + //so wait until we have per-frame diagnostics. + //this was tested using Princess Debut (US) after proceeding through the intro and getting the tiara. + //After much research, I determined that this was caused by the game feeding in a totally jacked matrix + //to mult4x4 from 0x02129B80 (after feeding two other valid matrices) + //the game seems to internally index these as: ?, 0x37, 0x2B <-- error + //but, man... this is seriously messed up. there must be something going wrong. + //maybe it has something to do with what looks like a mirror room effect that is going on during this time? + //PROGINFO("ERROR: shininess table out of bounds.\n maybe an emulator error; maybe a non-unit normal; setting to 0\n"); + shininessIndex = 0; + } + shininessLevel = shininessTable[shininessIndex]; } for(c = 0; c < 3; c++) diff --git a/desmume/src/rasterize.cpp b/desmume/src/rasterize.cpp index ddfef3aea..87971143e 100644 --- a/desmume/src/rasterize.cpp +++ b/desmume/src/rasterize.cpp @@ -771,6 +771,7 @@ static void drawscanline(edge_fx_fl *pLeft, edge_fx_fl *pRight) { if(x<0 || x>255) { printf("rasterizer rendering at x=%d! oops!\n",x); + return; } pixel(adr,color[0],color[1],color[2],u,v,1.0f/invw,z); adr++; @@ -1216,10 +1217,12 @@ static void SoftRastRender() vert.coord[0] += viewport.x; vert.coord[1] *= viewport.height; vert.coord[1] += viewport.y; - if(vert.coord[1]>192||vert.color[1]<0) { - int zzz=9; - } vert.coord[1] = 192 - vert.coord[1]; + + //well, i guess we need to do this to keep Princess Debut from rendering huge polys. + //there must be something strange going on + vert.coord[0] = max(0.0f,min(256.0f,vert.coord[0])); + vert.coord[1] = max(0.0f,min(192.0f,vert.coord[1])); } }