changeset 2440:2b10278bc7ac

some more memory access fixed
author Grumpy7
date Thu, 24 Jul 2014 01:10:50 +0200
parents ea7748f4dc60
children 135b2116db9d
files GUIProgressBar.cpp Items.h OpenALSoundProvider.h Render.cpp Spells.cpp
diffstat 5 files changed, 23 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/GUIProgressBar.cpp	Wed Jul 23 22:25:13 2014 +0200
+++ b/GUIProgressBar.cpp	Thu Jul 24 01:10:50 2014 +0200
@@ -122,21 +122,18 @@
 {
   int v3; // edi@7
 
+  pLoadingBg.Release();
   if ( this->uType == 1 )
   {
-    if ( !this->pLoadingBg.pPixels )
-      return;
     if ( this->uProgressCurrent != this->uProgressMax )
     {
       this->uProgressCurrent = this->uProgressMax - 1;
       Progress();
     }
-    free(this->pLoadingBg.pPixels);
     v3 = (int)&this->pLoadingProgress.pLevelOfDetail0_prolly_alpha_mask;
     free(this->pLoadingProgress.pLevelOfDetail0_prolly_alpha_mask);
     free(this->pLoadingProgress.pPalette16);
     this->pLoadingProgress.pPalette16 = 0;
-    this->pLoadingBg.pPixels = 0;
   }
   else
   {
--- a/Items.h	Wed Jul 23 22:25:13 2014 +0200
+++ b/Items.h	Thu Jul 24 01:10:50 2014 +0200
@@ -225,6 +225,7 @@
   static void PopulateSpecialBonusMap();
   static void PopulateRegularBonusMap();
   static void PopulateArtifactBonusMap();
+  static void ClearItemBonusMaps();
 
   void GetItemBonusSpecialEnchantment(Player* owner, CHARACTER_ATTRIBUTE_TYPE attrToGet, int* additiveBonus, int* halfSkillBonus);
   void GetItemBonusArtifact(Player* owner, CHARACTER_ATTRIBUTE_TYPE attrToGet, int* bonusSum);
--- a/OpenALSoundProvider.h	Wed Jul 23 22:25:13 2014 +0200
+++ b/OpenALSoundProvider.h	Thu Jul 24 01:10:50 2014 +0200
@@ -27,11 +27,19 @@
       this->context = nullptr;
     }
 
+    inline ~OpenALSoundProvider()
+    {
+      Release();
+    }
+
     inline bool Initialize()
     {
+
       auto device_names = alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
       if (!device_names)
+      {
         device_names = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
+      }
       if (device_names)
       {
         for (auto device_name = device_names; device_name[0]; device_name += strlen(device_name))
@@ -68,12 +76,10 @@
       if (context)
       {
         alcDestroyContext(context);
-        context = nullptr;
       }
       if (device)
       {
         alcCloseDevice(device);
-        device = nullptr;
       }
     }
 
--- a/Render.cpp	Wed Jul 23 22:25:13 2014 +0200
+++ b/Render.cpp	Thu Jul 24 01:10:50 2014 +0200
@@ -742,7 +742,7 @@
   IDirect3D3 *pDirect3D3; // [sp+4C4h] [bp-38h]@18
   int is_there_a_compatible_screen_mode; // [sp+4C8h] [bp-34h]@16
   RenderD3D_D3DDevDesc v20; // [sp+4CCh] [bp-30h]@1
-  LPDIRECTDRAW pDirectDraw; // [sp+4F4h] [bp-8h]@4
+  LPDIRECTDRAW pDirectDraw = nullptr; // [sp+4F4h] [bp-8h]@4
   IDirectDraw4 *pDirectDraw4; // [sp+4F8h] [bp-4h]@7
 
   v4 = strlen(lpDriverName);
@@ -1259,24 +1259,24 @@
   v3 = 0;
   do
   {
-    free(v1->pAvailableDevices[v3].pDriverName);
+    delete[] v1->pAvailableDevices[v3].pDriverName;
     v1->pAvailableDevices[v3].pDriverName = nullptr;
-    free(v1->pAvailableDevices[v3].pDeviceDesc);
+    delete[] v1->pAvailableDevices[v3].pDeviceDesc;
     v1->pAvailableDevices[v3].pDeviceDesc = nullptr;
-    free(v1->pAvailableDevices[v3].pDDraw4DevDesc);
+    delete[] v1->pAvailableDevices[v3].pDDraw4DevDesc;
     v1->pAvailableDevices[v3].pDDraw4DevDesc = nullptr;
-    free(v1->pAvailableDevices[v3].pDirectDrawGUID);
+    delete v1->pAvailableDevices[v3].pDirectDrawGUID;
     v1->pAvailableDevices[v3].pDirectDrawGUID = nullptr;
-    free(v1->pAvailableDevices[v3].pName);
+    delete[] v1->pAvailableDevices[v3].pName;
     v1->pAvailableDevices[v3].pName = nullptr;
-    free(v1->pAvailableDevices[v3].pDescription);
+    delete[] v1->pAvailableDevices[v3].pDescription;
     v1->pAvailableDevices[v3].pDescription = nullptr;
-    free(v1->pAvailableDevices[v3].pGUID);
+    delete v1->pAvailableDevices[v3].pGUID;
     v1->pAvailableDevices[v3].pGUID = nullptr;
     ++v3;
   }
   while ( v3 < 4 );
-  free(v1->pAvailableDevices);
+  delete[] v1->pAvailableDevices;
   v1->pAvailableDevices = 0;
   v4 = v1->pViewport;
   if ( v4 )
@@ -8447,7 +8447,7 @@
     fclose(this->pFile);
     for (uint i = 0; i < this->uNumItems; i++)
     {
-      free(this->pSpriteNames[i]);
+      delete[] this->pSpriteNames[i];
     }
   }
   return true;
--- a/Spells.cpp	Wed Jul 23 22:25:13 2014 +0200
+++ b/Spells.cpp	Thu Jul 24 01:10:50 2014 +0200
@@ -332,9 +332,10 @@
 	pSpellsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spells.txt", 0);
 
 	strtok(pSpellsTXT_Raw, "\r");
-	strtok(NULL, "\r");
 	for(int i=1; i<100; ++i) 
-	{
+  {
+    if ((i % (11 - 1) )==0)
+      strtok(NULL, "\r");
     test_string=strtok(NULL, "\r")+1;
     auto tokens = Tokenize(test_string, '\t');
     pInfos[i].pName=RemoveQuotes(tokens[2]);
@@ -350,8 +351,6 @@
     pSpellDatas[i].stats |= strchr(tokens[10], 'e') || strchr(tokens[10], 'E') ? 2 : 0;
     pSpellDatas[i].stats |= strchr(tokens[10], 'c') || strchr(tokens[10], 'C') ? 4 : 0;
     pSpellDatas[i].stats |= strchr(tokens[10], 'x') || strchr(tokens[10], 'X') ? 8 : 0;
-    if ((i % 11)==0)
-      strtok(NULL, "\r");
   }
 }
 //----- (00448DF8) --------------------------------------------------------