From 188c020ae05b4287c6d539df4916f2962903bf83 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sat, 30 Apr 2011 11:46:23 +0000 Subject: [PATCH] Fix reading outside buffer, when terrain alpha maps are 8-bit. Change alpha map composite texture to 8-bit to avoid wasting memory. Warn about non-square alpha maps. This was SVN commit r9360. --- source/renderer/Renderer.cpp | 59 ++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index 591e1e762b..7ef492067c 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -1699,13 +1699,6 @@ void CRenderer::BindTexture(int unit,GLuint tex) } } -static inline void CopyTriple(unsigned char* dst,const unsigned char* src) -{ - dst[0]=src[0]; - dst[1]=src[1]; - dst[2]=src[2]; -} - /////////////////////////////////////////////////////////////////////////////////////////////////// // LoadAlphaMaps: load the 14 default alpha maps, pack them into one composite texture and // calculate the coordinate of each alphamap within this packed texture @@ -1755,8 +1748,10 @@ int CRenderer::LoadAlphaMaps() // get its size and make sure they are all equal. // (the packing algo assumes this) - size_t this_width = 0, this_bpp = 0; // fail-safe - (void)ogl_tex_get_size(textures[i], &this_width, 0, &this_bpp); + size_t this_width = 0, this_height = 0, this_bpp = 0; // fail-safe + (void)ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp); + if(this_width != this_height) + DEBUG_DISPLAY_ERROR(L"Alpha maps are not square"); // .. first iteration: establish size if(i == 0) { @@ -1775,55 +1770,53 @@ int CRenderer::LoadAlphaMaps() size_t total_w = round_up_to_pow2(tile_w * NumAlphaMaps); size_t total_h = base; debug_assert(is_pow2(total_h)); shared_ptr data; - AllocateAligned(data, total_w*total_h*3, maxSectorSize); + AllocateAligned(data, total_w*total_h, maxSectorSize); // for each tile on row - for(size_t i=0;i