Browse Source

Added some checks & logs for empty def names, but it only delays the crash.

DjWarmonger 10 years ago
parent
commit
57637dd71a
4 changed files with 24 additions and 2 deletions
  1. 10 0
      client/Graphics.cpp
  2. 9 2
      client/mapHandler.cpp
  3. 1 0
      lib/VCMI_lib.vcxproj
  4. 4 0
      lib/VCMI_lib.vcxproj.filters

+ 10 - 0
client/Graphics.cpp

@@ -373,11 +373,21 @@ void Graphics::loadFonts()
 
 CDefEssential * Graphics::getDef( const CGObjectInstance * obj )
 {
+	if (obj->appearance.animationFile.empty())
+	{
+		logGlobal->warnStream() << boost::format("Def name for (%d,%d) is empty!") % obj->id % obj->subID;
+		return nullptr;
+	}
 	return advmapobjGraphics[obj->appearance.animationFile];
 }
 
 CDefEssential * Graphics::getDef( const ObjectTemplate & info )
 {
+	if (info.animationFile.empty())
+	{
+		logGlobal->warnStream() << boost::format("Def name for obj (%d,%d) is empty!") % info.id % info.subid;
+		return nullptr;
+	}
 	return advmapobjGraphics[info.animationFile];
 }
 

+ 9 - 2
client/mapHandler.cpp

@@ -860,8 +860,15 @@ void CMapHandler::CMapBlitter::drawObjects(SDL_Surface * targetSurf, const Terra
 		
 		if (!graphics->getDef(obj))
 			processDef(obj->appearance);
-		if (!graphics->getDef(obj) && !obj->appearance.animationFile.empty())
-			logGlobal->errorStream() << "Failed to load image " << obj->appearance.animationFile;
+		if (!graphics->getDef(obj))
+		{
+			if (!obj->appearance.animationFile.empty())
+				logGlobal->errorStream() << "Failed to load image " << obj->appearance.animationFile;
+			else
+				logGlobal->warnStream() << boost::format("Def name for (%d,%d) is empty!") % obj->id % obj->subID;
+
+			continue;
+		}
 
 		if (!canDrawObject(obj))
 			continue;

+ 1 - 0
lib/VCMI_lib.vcxproj

@@ -364,6 +364,7 @@
     <ClInclude Include="spells\CreatureSpellMechanics.h" />
     <ClInclude Include="spells\CSpellHandler.h" />
     <ClInclude Include="spells\ISpellMechanics.h" />
+    <ClInclude Include="spells\Magic.h" />
     <ClInclude Include="spells\SpellMechanics.h" />
     <ClInclude Include="spells\ViewSpellInt.h" />
     <ClInclude Include="StartInfo.h" />

+ 4 - 0
lib/VCMI_lib.vcxproj.filters

@@ -225,6 +225,7 @@
     <ClCompile Include="spells\CreatureSpellMechanics.cpp">
       <Filter>spells</Filter>
     </ClCompile>
+    <ClCompile Include="mapping\CDrawRoadsOperation.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="CCreatureSet.h">
@@ -533,5 +534,8 @@
     <ClInclude Include="spells\SpellMechanics.h">
       <Filter>spells</Filter>
     </ClInclude>
+    <ClInclude Include="spells\Magic.h">
+      <Filter>spells</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>