Added a couple of null guards against invalid quads / textures in the render() call, with JLOG calls to trace this out if we should hit one of these cases. (Reformatted tabbing in the function while I was there.)

This commit is contained in:
wrenczes@gmail.com
2011-01-11 10:36:15 +00:00
parent 2063e27681
commit eac6d74ebd
+156 -146
View File
@@ -534,176 +534,186 @@ void JRenderer::PlotArray(float *x, float *y, int count, PIXEL_TYPE color)
// v3---v4 // v3---v4
void JRenderer::RenderQuad(JQuad* quad, float xo, float yo, float angle, float xScale, float yScale) void JRenderer::RenderQuad(JQuad* quad, float xo, float yo, float angle, float xScale, float yScale)
{ {
if (mCurrentTextureFormat != quad->mTex->mTextureFormat){ if (quad == NULL)
mCurrentTextureFormat = quad->mTex->mTextureFormat; {
sceGuTexMode(mCurrentTextureFormat, 0, 0, mSwizzle); JLOG("JRenderer::RenderQuad: NULL quad pointer!");
} return;
}
if (mCurrentTex != quad->mTex->mTexId) if (quad->mTex == NULL)
{ {
sceGuTexImage(0, quad->mTex->mTexWidth, quad->mTex->mTexHeight, quad->mTex->mTexWidth, quad->mTex->mBits); JLOG("JRenderer::RenderQuad:: invalid texture!");
mCurrentTex = quad->mTex->mTexId; return;
} }
if (mCurrentBlend != quad->mBlend) if (mCurrentTextureFormat != quad->mTex->mTextureFormat)
{ {
sceGuTexFunc(quad->mBlend, GU_TCC_RGBA); mCurrentTextureFormat = quad->mTex->mTextureFormat;
mCurrentBlend = quad->mBlend; sceGuTexMode(mCurrentTextureFormat, 0, 0, mSwizzle);
} }
if (mCurrentTex != quad->mTex->mTexId)
{
sceGuTexImage(0, quad->mTex->mTexWidth, quad->mTex->mTexHeight, quad->mTex->mTexWidth, quad->mTex->mBits);
mCurrentTex = quad->mTex->mTexId;
}
if (mCurrentBlend != quad->mBlend)
{
sceGuTexFunc(quad->mBlend, GU_TCC_RGBA);
mCurrentBlend = quad->mBlend;
}
//float destWidth = quad->mWidth*quad->mScaleX; //float destWidth = quad->mWidth*quad->mScaleX;
float destHeight = quad->mHeight*yScale; float destHeight = quad->mHeight*yScale;
float x = xo - quad->mHotSpotX*xScale; float x = xo - quad->mHotSpotX*xScale;
float y = yo - quad->mHotSpotY*yScale; float y = yo - quad->mHotSpotY*yScale;
float start, end; float start, end;
float width; float width;
float destWidth; float destWidth;
float fixedWidth = SLICE_SIZE_F*xScale; float fixedWidth = SLICE_SIZE_F*xScale;
float xx, yy; float xx, yy;
float cosAngle = cosf(angle); float cosAngle = cosf(angle);
float sinAngle = sinf(angle); float sinAngle = sinf(angle);
if (quad->mHFlipped)// || quad->mVFlipped) if (quad->mHFlipped)// || quad->mVFlipped)
{ {
for (end = quad->mX, start = quad->mX+quad->mWidth; start > end; start -= SLICE_SIZE_F) for (end = quad->mX, start = quad->mX+quad->mWidth; start > end; start -= SLICE_SIZE_F)
{ {
// allocate memory on the current display list for temporary storage // allocate memory on the current display list for temporary storage
// in order to rotate, we use 4 vertices this time // in order to rotate, we use 4 vertices this time
struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(4 * sizeof(struct Vertex)); struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(4 * sizeof(struct Vertex));
if ((start - SLICE_SIZE_F) > end) if ((start - SLICE_SIZE_F) > end)
{ {
width = SLICE_SIZE_F; width = SLICE_SIZE_F;
destWidth = fixedWidth; destWidth = fixedWidth;
} }
else else
{ {
width = start-end; width = start-end;
destWidth = width*xScale; destWidth = width*xScale;
} }
vertices[0].u = start; vertices[0].u = start;
vertices[0].v = quad->mY; vertices[0].v = quad->mY;
vertices[0].color = quad->mColor[0];//.color; vertices[0].color = quad->mColor[0];//.color;
vertices[0].x = x; vertices[0].x = x;
vertices[0].y = y; vertices[0].y = y;
vertices[0].z = 0.0f; vertices[0].z = 0.0f;
vertices[2].u = start - width; vertices[2].u = start - width;
vertices[2].v = quad->mY; vertices[2].v = quad->mY;
vertices[2].color = quad->mColor[2];//.color; vertices[2].color = quad->mColor[2];//.color;
vertices[2].x = x + destWidth; vertices[2].x = x + destWidth;
vertices[2].y = y; vertices[2].y = y;
vertices[2].z = 0.0f; vertices[2].z = 0.0f;
vertices[1].u = start; vertices[1].u = start;
vertices[1].v = quad->mY + quad->mHeight; vertices[1].v = quad->mY + quad->mHeight;
vertices[1].color = quad->mColor[1];//.color; vertices[1].color = quad->mColor[1];//.color;
vertices[1].x = x; vertices[1].x = x;
vertices[1].y = y + destHeight; vertices[1].y = y + destHeight;
vertices[1].z = 0.0f; vertices[1].z = 0.0f;
vertices[3].u = start - width; vertices[3].u = start - width;
vertices[3].v = quad->mY + quad->mHeight; vertices[3].v = quad->mY + quad->mHeight;
vertices[3].color = quad->mColor[3];//.color; vertices[3].color = quad->mColor[3];//.color;
vertices[3].x = x + destWidth; vertices[3].x = x + destWidth;
vertices[3].y = y + destHeight; vertices[3].y = y + destHeight;
vertices[3].z = 0.0f; vertices[3].z = 0.0f;
if (quad->mVFlipped) if (quad->mVFlipped)
{ {
Swap(&vertices[0].v, &vertices[2].v); Swap(&vertices[0].v, &vertices[2].v);
Swap(&vertices[1].v, &vertices[3].v); Swap(&vertices[1].v, &vertices[3].v);
} }
if (angle != 0.0f) if (angle != 0.0f)
{ {
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
{ {
xx = (cosAngle*(vertices[i].x-xo) - sinAngle*(vertices[i].y-yo) + xo); xx = (cosAngle*(vertices[i].x-xo) - sinAngle*(vertices[i].y-yo) + xo);
yy = (sinAngle*(vertices[i].x-xo) + cosAngle*(vertices[i].y-yo) + yo); yy = (sinAngle*(vertices[i].x-xo) + cosAngle*(vertices[i].y-yo) + yo);
vertices[i].x = xx; vertices[i].x = xx;
vertices[i].y = yy; vertices[i].y = yy;
} }
} }
x += destWidth; x += destWidth;
sceGuDrawArray(GU_TRIANGLE_STRIP,GU_TEXTURE_32BITF|TEXTURE_COLOR_FORMAT|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices); sceGuDrawArray(GU_TRIANGLE_STRIP,GU_TEXTURE_32BITF|TEXTURE_COLOR_FORMAT|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices);
} }
} }
else else
{ {
for (start = quad->mX, end = quad->mX+quad->mWidth; start < end; start += SLICE_SIZE_F) for (start = quad->mX, end = quad->mX+quad->mWidth; start < end; start += SLICE_SIZE_F)
{ {
// allocate memory on the current display list for temporary storage // allocate memory on the current display list for temporary storage
// in order to rotate, we use 4 vertices this time // in order to rotate, we use 4 vertices this time
struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(4 * sizeof(struct Vertex)); struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(4 * sizeof(struct Vertex));
if ((start + SLICE_SIZE_F) < end) if ((start + SLICE_SIZE_F) < end)
{ {
width = SLICE_SIZE_F; width = SLICE_SIZE_F;
destWidth = fixedWidth; destWidth = fixedWidth;
} }
else else
{ {
width = end-start; width = end-start;
destWidth = width*xScale; destWidth = width*xScale;
} }
vertices[0].u = start; vertices[0].u = start;
vertices[0].v = quad->mY; vertices[0].v = quad->mY;
vertices[0].color = quad->mColor[0];//.color; vertices[0].color = quad->mColor[0];//.color;
vertices[0].x = x; vertices[0].x = x;
vertices[0].y = y; vertices[0].y = y;
vertices[0].z = 0.0f; vertices[0].z = 0.0f;
vertices[2].u = start + width; vertices[2].u = start + width;
vertices[2].v = quad->mY; vertices[2].v = quad->mY;
vertices[2].color = quad->mColor[2];//.color; vertices[2].color = quad->mColor[2];//.color;
vertices[2].x = x + destWidth; vertices[2].x = x + destWidth;
vertices[2].y = y; vertices[2].y = y;
vertices[2].z = 0.0f; vertices[2].z = 0.0f;
vertices[1].u = start; vertices[1].u = start;
vertices[1].v = quad->mY + quad->mHeight; vertices[1].v = quad->mY + quad->mHeight;
vertices[1].color = quad->mColor[1];//.color; vertices[1].color = quad->mColor[1];//.color;
vertices[1].x = x; vertices[1].x = x;
vertices[1].y = y + destHeight; vertices[1].y = y + destHeight;
vertices[1].z = 0.0f; vertices[1].z = 0.0f;
vertices[3].u = start + width; vertices[3].u = start + width;
vertices[3].v = quad->mY + quad->mHeight; vertices[3].v = quad->mY + quad->mHeight;
vertices[3].color = quad->mColor[3];//.color; vertices[3].color = quad->mColor[3];//.color;
vertices[3].x = x + destWidth; vertices[3].x = x + destWidth;
vertices[3].y = y + destHeight; vertices[3].y = y + destHeight;
vertices[3].z = 0.0f; vertices[3].z = 0.0f;
if (quad->mVFlipped) if (quad->mVFlipped)
{ {
Swap(&vertices[0].v, &vertices[2].v); Swap(&vertices[0].v, &vertices[2].v);
Swap(&vertices[1].v, &vertices[3].v); Swap(&vertices[1].v, &vertices[3].v);
} }
if (angle != 0.0f) if (angle != 0.0f)
{ {
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
{ {
xx = (cosAngle*(vertices[i].x-xo) - sinAngle*(vertices[i].y-yo) + xo); xx = (cosAngle*(vertices[i].x-xo) - sinAngle*(vertices[i].y-yo) + xo);
yy = (sinAngle*(vertices[i].x-xo) + cosAngle*(vertices[i].y-yo) + yo); yy = (sinAngle*(vertices[i].x-xo) + cosAngle*(vertices[i].y-yo) + yo);
vertices[i].x = xx; vertices[i].x = xx;
vertices[i].y = yy; vertices[i].y = yy;
} }
} }
x += destWidth; x += destWidth;
sceGuDrawArray(GU_TRIANGLE_STRIP,GU_TEXTURE_32BITF|TEXTURE_COLOR_FORMAT|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices); sceGuDrawArray(GU_TRIANGLE_STRIP,GU_TEXTURE_32BITF|TEXTURE_COLOR_FORMAT|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices);
} }
} }
} }