gsdx mipmap: improve robustness to avoid potential crash

This commit is contained in:
Gregory Hainaut 2016-09-26 09:27:03 +02:00
parent ebb2a8ad5a
commit be9995bd1e
2 changed files with 16 additions and 2 deletions

View File

@ -516,12 +516,23 @@ void GSRendererHW::Draw()
TEX0 = GetTex0Layer(lod);
// FIXME: previous round lod is likely wrong. Following code is a workaround until it is done properly
// Ratchet & Clank set an address of 0 on invalid layer. Address 0 will be really awkward
// for a mipmap layer. So use it to avoid invalid data
if (TEX0.TBP0 == 0) {
GL_INS("Warning invalid lod %d", lod);
lod++;
if (lod < mxl) {
lod++;
} else {
lod--;
}
TEX0 = GetTex0Layer(lod);
// Experience: will people complain more about missing or invalid texture ? The bets are open :)
if (TEX0.TBP0 == 0) {
fprintf(stderr, "Invalid mipmap layer\n");
throw GSDXRecoverableError();
}
}
MIP_CLAMP.MINU >>= lod;

View File

@ -3120,7 +3120,10 @@ GIFRegTEX0 GSState::GetTex0Layer(int lod)
TEX0.TBW = m_context->MIPTBP2.TBW6;
break;
default:
__assume(0);
fprintf(stderr, "GetTex0Layer bad parameter. Fix your code!\n");
lod = 6;
TEX0.TBP0 = m_context->MIPTBP2.TBP6;
TEX0.TBW = m_context->MIPTBP2.TBW6;
}
// Correct the texture size