Skip to content

Commit

Permalink
- made the tile size getters a bit more robust.
Browse files Browse the repository at this point in the history
They should not crash on invalid sprites.
  • Loading branch information
coelckers committed Apr 17, 2021
1 parent d2c9b59 commit cd58b1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion source/core/textures/buildtiles.cpp
Expand Up @@ -820,7 +820,7 @@ void tileUpdateAnimations()
{
for (int i = 0; i < MAXTILES; i++)
{
if (picanm[i].sf & PICANM_ANIMTYPE_MASK)
if (TileFiles.tiledata[i].picanm.sf & PICANM_ANIMTYPE_MASK)
{
int j = i + animateoffs(i, 0);

Expand Down
16 changes: 10 additions & 6 deletions source/core/textures/buildtiles.h
Expand Up @@ -407,25 +407,29 @@ extern PicAnm picanm;

inline int tileWidth(int num)
{
assert(num < MAXTILES);
assert((unsigned)num < MAXTILES);
if ((unsigned)num >= MAXTILES) return 1;
return (int)TileFiles.tiledata[num].texture->GetDisplayWidth();
}

inline int tileHeight(int num)
{
assert(num < MAXTILES);
assert((unsigned)num < MAXTILES);
if ((unsigned)num >= MAXTILES) return 1;
return (int)TileFiles.tiledata[num].texture->GetDisplayHeight();
}

inline int tileLeftOffset(int num)
{
assert(num < MAXTILES);
assert((unsigned)num < MAXTILES);
if ((unsigned)num >= MAXTILES) return 0;
return (int)TileFiles.tiledata[num].texture->GetDisplayLeftOffset();
}

inline int tileTopOffset(int num)
{
assert(num < MAXTILES);
assert((unsigned)num < MAXTILES);
if ((unsigned)num >= MAXTILES) return 0;
return (int)TileFiles.tiledata[num].texture->GetDisplayTopOffset();
}

Expand All @@ -440,11 +444,11 @@ int32_t animateoffs(int const tilenum, int fakevar);

inline FGameTexture* tileGetTexture(int tile, bool animate = false)
{
assert(tile < MAXTILES);
assert((unsigned)tile < MAXTILES);
if (tile < 0 || tile >= MAXTILES) return nullptr;
if (animate)
{
if (picanm[tile].sf & PICANM_ANIMTYPE_MASK)
if (TileFiles.tiledata[tile].picanm.sf & PICANM_ANIMTYPE_MASK)
tile += animateoffs(tile, 0);

}
Expand Down

0 comments on commit cd58b1d

Please sign in to comment.