From dba2de5e209f24b0091c736fa88dc80795b9f100 Mon Sep 17 00:00:00 2001
From: D-AIRY <admin@ds-servers.com>
Date: Mon, 30 Sep 2019 11:28:28 +0300
Subject: [PATCH] Some cleanup

---
 source/SkyXEngine.h    |  2 +-
 source/common          |  2 +-
 source/gui/Font.cpp    | 41 +++++++++++++++++++----------------------
 source/gui/SXGUI.cpp   |  1 +
 source/gui/Texture.cpp |  1 +
 source/gui/Texture.h   |  2 +-
 6 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/source/SkyXEngine.h b/source/SkyXEngine.h
index 7625d492c..5c3a2e9de 100644
--- a/source/SkyXEngine.h
+++ b/source/SkyXEngine.h
@@ -292,7 +292,7 @@ QT стиль документирования (!) и QT_AUTOBRIEF - корот
 #ifndef __SKYXENGINE_H
 #define __SKYXENGINE_H
 
-#define SKYXENGINE_VERSION "X.4.1-dev"
+#define SKYXENGINE_VERSION "X.4.2-dev"
 
 #define SKYXENGINE_VERSION4EDITORS "SkyXEngine version " ## SKYXENGINE_VERSION
 
diff --git a/source/common b/source/common
index b2578fec1..b38c53dda 160000
--- a/source/common
+++ b/source/common
@@ -1 +1 @@
-Subproject commit b2578fec1d058a3305261e0e359731e14e07ca16
+Subproject commit b38c53ddacfd749e87aa2b34d2010af39836a27f
diff --git a/source/gui/Font.cpp b/source/gui/Font.cpp
index 4ef63a208..c8bb1a476 100644
--- a/source/gui/Font.cpp
+++ b/source/gui/Font.cpp
@@ -48,7 +48,7 @@ namespace gui
 		}
 		fwrite(&m_header, sizeof(SXFheader), 1, pF);
 		UINT c = 0;
-		for(UINT i = 0; i < m_chars.size(); i++)
+		for(UINT i = 0, l = m_chars.size(); i < l; i++)
 		{
 			if(m_chars[i].id != 0)
 			{
@@ -56,7 +56,7 @@ namespace gui
 				c++;
 			}
 		}
-		UINT w, h;
+		uint32_t w, h;
 		byte * data;
 		for(UINT i = 0; i < m_vpTextures.size(); i++)
 		{
@@ -100,25 +100,19 @@ namespace gui
 				break;
 			}
 			StringW file = m_pFontManager->getResourceDir() + L"/fonts/" + m_szFontName + suf + L".ttf";
-			String _f;
-			for(UINT i = 0; i < file.length(); i++)
-			{
-				_f += (char)file[i];
-			}
+			String _f(file);
+			
 			if(FT_New_Face(m_pFontManager->requestFT(), _f.c_str(), 0, &m_pFTfontFace))
 			{
-				printf("Unable to load \"%s\" font\n", String(file).c_str());
+				printf("Unable to load \"%s\" font\n", _f.c_str());
 				if(m_style != STYLE_NONE)
 				{
 					file = m_pFontManager->getResourceDir() + L"/fonts/" + m_szFontName + L".ttf";
-					_f = "";
-					for(UINT i = 0; i < file.length(); i++)
-					{
-						_f += (char)file[i];
-					}
+					_f = file;
+					
 					if(FT_New_Face(m_pFontManager->requestFT(), _f.c_str(), 0, &m_pFTfontFace))
 					{
-						printf("Unable to load \"%s\" font\n", String(file).c_str());
+						printf("Unable to load \"%s\" font\n", _f.c_str());
 					}
 					else
 					{
@@ -259,14 +253,15 @@ namespace gui
 			memset(d.data, 0, sizeof(byte)* d.w * d.h * 4);
 			int cc = 0;
 			FT_Bitmap * bitmap = &g->bitmap;
+			FT_Bitmap tempbitmapmono;
 			if(g->bitmap.pixel_mode == FT_PIXEL_MODE_MONO)
 			{
-				FT_Bitmap tempbitmap;
-				FT_Bitmap_New(&tempbitmap);
-				FT_Bitmap_Convert(m_pFontManager->requestFT(), bitmap, &tempbitmap, 1);
-				bitmap = &tempbitmap;
-				byte * buf = tempbitmap.buffer;
-				for(UINT i = 0; i<tempbitmap.rows*tempbitmap.pitch; i++)
+				//FT_Bitmap tempbitmap;
+				FT_Bitmap_New(&tempbitmapmono);
+				FT_Bitmap_Convert(m_pFontManager->requestFT(), bitmap, &tempbitmapmono, 1);
+				bitmap = &tempbitmapmono;
+				byte * buf = tempbitmapmono.buffer;
+				for(UINT i = 0; i<tempbitmapmono.rows*tempbitmapmono.pitch; i++)
 				{
 					if(*buf > 0) *buf = 255;
 					buf++;
@@ -316,8 +311,10 @@ namespace gui
 					}
 				}
 			}
-
-			FT_Bitmap_Done(m_pFontManager->requestFT(), bitmap);
+			if(g->bitmap.pixel_mode == FT_PIXEL_MODE_MONO)
+			{
+				FT_Bitmap_Done(m_pFontManager->requestFT(), &tempbitmapmono);
+			}
 
 			d.c = m_szFontChars[i]; // FIXME: Fix for two 32bit chars
 			for(UINT ii = 0; ii < list.size(); ii++)
diff --git a/source/gui/SXGUI.cpp b/source/gui/SXGUI.cpp
index 25f2f0bd9..c5b1d45ce 100644
--- a/source/gui/SXGUI.cpp
+++ b/source/gui/SXGUI.cpp
@@ -848,6 +848,7 @@ BOOL APIENTRY DllMain(HMODULE hModule,
 	switch(ul_reason_for_call)
 	{
 	case DLL_PROCESS_ATTACH:
+		//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF);
 		break;
 	case DLL_THREAD_ATTACH:
 		break;
diff --git a/source/gui/Texture.cpp b/source/gui/Texture.cpp
index cb61f8ccf..9be1d734c 100644
--- a/source/gui/Texture.cpp
+++ b/source/gui/Texture.cpp
@@ -37,6 +37,7 @@ namespace gui
 
 		if(!(bt->m_pTexture = GetGUI()->getDevice()->createTexture2D(w, h, isRT ? 1 : 0, isRT ? GX_TEXFLAG_RENDERTARGET | (isAutoResizeRT ? GX_TEXFLAG_AUTORESIZE : 0) : 0, GXFMT_A8R8G8B8, pInitData)))
 		{
+			mem_delete(bt);
 			return(NULL);
 		}
 
diff --git a/source/gui/Texture.h b/source/gui/Texture.h
index 708ea6a32..8e834ee39 100644
--- a/source/gui/Texture.h
+++ b/source/gui/Texture.h
@@ -73,7 +73,7 @@ namespace gui
 	protected:
 		StringW m_wsResourceDir;
 		AssotiativeArray<StringW, CTexture*> m_mTextures;
-		CPITexture m_pCurrentTex;
+		CPITexture m_pCurrentTex = NULL;
 	};
 };
 
-- 
GitLab