From 5a4ad0dca6f60e91fc40e7d860daccd9953eb3df Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 23 Apr 2019 20:08:13 +1000 Subject: [PATCH] Fix crashing when using terrain.png less than 16 wide, fix crashing when using terrain.png of size 16x32 (thanks xnotx123) --- src/Game.c | 5 +++++ src/Menus.c | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Game.c b/src/Game.c index 288d4beff..4d330f9c3 100644 --- a/src/Game.c +++ b/src/Game.c @@ -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(); diff --git a/src/Menus.c b/src/Menus.c index 41eddabd0..ec0a2127b 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -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;