Skip to content

Commit

Permalink
Fix crashes from out-of-bounds shadow drawing (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Aug 5, 2013
1 parent 93b02a6 commit 0c280d2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/cdogs/actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,27 @@ static void DrawShadow(Vector2i pos)
const int dy = 6;
for (drawPos.y = pos.y - dy; drawPos.y < pos.y + dy; drawPos.y++)
{
if (drawPos.y >= gGraphicsDevice.clipping.bottom)
{
break;
}
if (drawPos.y < gGraphicsDevice.clipping.top)
{
continue;
}
for (drawPos.x = pos.x - dx; drawPos.x < pos.x + dx; drawPos.x++)
{
// Calculate value tint based on distance from center
Vector2i scaledPos;
int distance2;
if (drawPos.x >= gGraphicsDevice.clipping.right)
{
break;
}
if (drawPos.y < gGraphicsDevice.clipping.left)
{
continue;
}
scaledPos.x = drawPos.x;
scaledPos.y = (drawPos.y - pos.y) * dx / dy + pos.y;
distance2 = DistanceSquared(scaledPos, pos);
Expand Down
16 changes: 12 additions & 4 deletions src/cdogs/hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ void HUDUpdate(HUD *hud, int ms)
}


static void DrawWeaponStatus(const Weapon *weapon, Vector2i pos, int flags)
{
CDogsTextStringSpecial(GunGetName(weapon->gun), flags, pos.x, pos.y);
}

void DrawHealth(int health, int maxHealth, int flags, GraphicsConfig *config)
{
char s[50];
Expand Down Expand Up @@ -182,7 +187,7 @@ void DrawHealth(int health, int maxHealth, int flags, GraphicsConfig *config)
#define HUD_PLACE_LEFT 0
#define HUD_PLACE_RIGHT 1
// Draw player's score, health etc.
void DrawPlayerStatus(
static void DrawPlayerStatus(
struct PlayerData *data, TActor *p, int placement, GraphicsConfig *config)
{
char s[50];
Expand All @@ -203,9 +208,12 @@ void DrawPlayerStatus(
}
if (p)
{
CDogsTextStringSpecial(s, flags, 5, 5 + 2 + 2 * CDogsTextHeight());
CDogsTextStringSpecial(
GunGetName(p->weapon.gun), flags, 5, 5 + 1 + CDogsTextHeight());
Vector2i pos;
pos.x = 5;
pos.y = 5 + 1 + CDogsTextHeight();
DrawWeaponStatus(&p->weapon, pos, flags);
pos.y += 1 + CDogsTextHeight();
CDogsTextStringSpecial(s, flags, pos.x, pos.y);
DrawHealth(p->health, gCharacterDesc[p->character].maxHealth, flags, config);
}
else
Expand Down

0 comments on commit 0c280d2

Please sign in to comment.