Fix crashing when using terrain.png less than 16 wide, fix crashing when using terrain.png of size 16x32 (thanks xnotx123)

This commit is contained in:
UnknownShadow200 2019-04-23 20:08:13 +10:00
parent 76b1f70fe4
commit 5a4ad0dca6
2 changed files with 12 additions and 3 deletions

View File

@ -134,6 +134,11 @@ bool Game_ChangeTerrainAtlas(Bitmap* atlas) {
Chat_AddRaw("&c Its height is less than its width.");
return false;
}
if (atlas->Width < ATLAS2D_TILES_PER_ROW) {
Chat_AddRaw("&cUnable to use terrain.png from the texture pack.");
Chat_AddRaw("&c It must be 16 or more pixels wide.");
return false;
}
if (Gfx.LostContext) return false;
Atlas_Free();

View File

@ -2961,7 +2961,11 @@ static bool WarningOverlay_IsAlways(void* screen, void* w) { return Menu_Index(s
/*########################################################################################################################*
*------------------------------------------------------TexIdsOverlay------------------------------------------------------*
*#########################################################################################################################*/
#define TEXID_OVERLAY_VERTICES_COUNT (ATLAS2D_TILES_PER_ROW * ATLAS2D_TILES_PER_ROW * 4)
/*########################################################################################################################*
*------------------------------------------------------TexIdsOverlay------------------------------------------------------*
*#########################################################################################################################*/
#define TEXID_OVERLAY_MAX_PER_PAGE (ATLAS2D_TILES_PER_ROW * ATLAS2D_TILES_PER_ROW)
#define TEXID_OVERLAY_VERTICES_COUNT (TEXID_OVERLAY_MAX_PER_PAGE * 4)
static struct TexIdsOverlay TexIdsOverlay_Instance;
static void TexIdsOverlay_ContextLost(void* screen) {
struct TexIdsOverlay* s = screen;
@ -3004,10 +3008,10 @@ static void TexIdsOverlay_RenderTerrain(struct TexIdsOverlay* s) {
tex.uv.U1 = 0.0f; tex.uv.U2 = UV2_Scale;
tex.Width = size; tex.Height = size;
for (i = 0; i < ATLAS2D_TILES_PER_ROW * ATLAS2D_TILES_PER_ROW;) {
for (i = 0; i < TEXID_OVERLAY_MAX_PER_PAGE;) {
ptr = vertices;
idx = Atlas1D_Index(i + s->BaseTexLoc);
end = i + Atlas1D.TilesPerAtlas;
end = min(i + Atlas1D.TilesPerAtlas, TEXID_OVERLAY_MAX_PER_PAGE);
for (; i < end; i++) {
tex.X = s->XOffset + Atlas2D_TileX(i) * size;