Program: 83624
Project: 83624
Buggy source:
@Override protected void onDraw(Canvas canvas){
  mGame.update();
  Matrix matrix=new Matrix();
{
    float scaleX=(float)mWidth / mBackgroundBitmap.getWidth();
    float scaleY=(float)mHeight / mBackgroundBitmap.getHeight();
    float scale=Math.max(scaleX,scaleY);
    matrix.postScale(scale,scale);
    matrix.postTranslate((scaleX - scale) * (mBackgroundBitmap.getWidth() / 2),(scaleY - scale) * (mBackgroundBitmap.getHeight() / 2));
    canvas.drawBitmap(mBackgroundBitmap,matrix,mBitmapPaint);
  }
  for (  int entityType : ENTITY_LAYERS) {
    float radius=Entity.Radii[entityType];
    radius*=2;
    float minXDrawable=0 - radius;
    float maxXDrawable=mWidth + radius;
    float minYDrawable=0 - radius;
    float maxYDrawable=mHeight + radius;
    for (int i=0; i < Game.NUM_PLAYERS; i++) {
      Player player=mGame.mPlayers[i];
      Bitmap[] entityBitmaps=mPlayerEntityBitmaps.get(player);
      for (      Entity entity : player.mEntities[entityType]) {
        if (entity.body.center.x > minXDrawable && entity.body.center.x < maxXDrawable && entity.body.center.y > minYDrawable && entity.body.center.y < maxYDrawable) {
          Bitmap bitmap=entityBitmaps[entity.type];
          float posX;
          float posY;
          if (mOrientation == Configuration.ORIENTATION_PORTRAIT) {
            posX=entity.body.center.x;
            posY=entity.body.center.y;
          }
 else {
            posY=320 - entity.body.center.x;
            posX=entity.body.center.y;
          }
          if (bitmap != null) {
            matrix.reset();
            float scaleX=entity.diameter / bitmap.getWidth();
            float scaleY=entity.diameter / bitmap.getHeight();
            float scale=Math.max(scaleX,scaleY);
            matrix.postScale(scale,scale);
            matrix.postTranslate(posX - (scale / scaleX) * entity.radius,posY - (scale / scaleY) * entity.radius);
            matrix.postRotate((float)Math.toDegrees(entity.heading + mAngleFudge),posX,posY);
            canvas.drawBitmap(bitmap,matrix,mBitmapPaint);
          }
          canvas.drawCircle(posX,posY,entity.radius,mBoundsPaints[i]);
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override protected void onDraw(Canvas canvas){
  mGame.update();
  if (mWidth == 0) {
    updateOrientation();
  }
  Matrix matrix=new Matrix();
{
    float scaleX=(float)mWidth / mBackgroundBitmap.getWidth();
    float scaleY=(float)mHeight / mBackgroundBitmap.getHeight();
    float scale=Math.max(scaleX,scaleY);
    matrix.postScale(scale,scale);
    matrix.postTranslate((scaleX - scale) * (mBackgroundBitmap.getWidth() / 2),(scaleY - scale) * (mBackgroundBitmap.getHeight() / 2));
    canvas.drawBitmap(mBackgroundBitmap,matrix,mBitmapPaint);
  }
  for (  int entityType : ENTITY_LAYERS) {
    float radius=Entity.Radii[entityType];
    radius*=2;
    float minXDrawable=0 - radius;
    float maxXDrawable=mWidth + radius;
    float minYDrawable=0 - radius;
    float maxYDrawable=mHeight + radius;
    for (int i=0; i < Game.NUM_PLAYERS; i++) {
      Player player=mGame.mPlayers[i];
      Bitmap[] entityBitmaps=mPlayerEntityBitmaps.get(player);
      for (      Entity entity : player.mEntities[entityType]) {
        float posX;
        float posY;
switch (mRotation) {
case Surface.ROTATION_0:
          posX=entity.body.center.x;
        posY=entity.body.center.y;
      break;
case Surface.ROTATION_90:
    posX=entity.body.center.y;
  posY=mHeight - entity.body.center.x;
break;
case Surface.ROTATION_180:
posX=mWidth - entity.body.center.x;
posY=mHeight - entity.body.center.y;
break;
case Surface.ROTATION_270:
default :
posX=mWidth - entity.body.center.y;
posY=entity.body.center.x;
break;
}
if (posX > minXDrawable && posX < maxXDrawable && posY > minYDrawable && posY < maxYDrawable) {
Bitmap bitmap=entityBitmaps[entity.type];
if (bitmap != null) {
matrix.reset();
float scaleX=entity.diameter / bitmap.getWidth();
float scaleY=entity.diameter / bitmap.getHeight();
float scale=Math.max(scaleX,scaleY);
matrix.postScale(scale,scale);
matrix.postTranslate(posX - (scale / scaleX) * entity.radius,posY - (scale / scaleY) * entity.radius);
matrix.postRotate((float)Math.toDegrees(entity.heading + mAngleFudge),posX,posY);
canvas.drawBitmap(bitmap,matrix,mBitmapPaint);
}
canvas.drawCircle(posX,posY,entity.radius,mBoundsPaints[i]);
}
}
}
}
}