Browse Source

Fix: deal with null map objects (reserved for heroes not on map)

Michał Zaremba 2 months ago
parent
commit
949b34a3cb

+ 3 - 0
mapeditor/mainwindow.cpp

@@ -618,6 +618,9 @@ void MainWindow::saveMap()
 
 
 	for(auto obj : controller.map()->objects)
 	for(auto obj : controller.map()->objects)
 	{
 	{
+		if(!obj)
+			continue;
+
 		if(obj->ID == Obj::HERO_PLACEHOLDER)
 		if(obj->ID == Obj::HERO_PLACEHOLDER)
 		{
 		{
 			auto hero = dynamic_cast<CGHeroPlaceholder *>(obj.get());
 			auto hero = dynamic_cast<CGHeroPlaceholder *>(obj.get());

+ 2 - 0
mapeditor/mapcontroller.cpp

@@ -742,6 +742,8 @@ ModCompatibilityInfo MapController::modAssessmentMap(const CMap & map)
 
 
 	for(auto obj : map.objects)
 	for(auto obj : map.objects)
 	{
 	{
+		if(!obj)
+			continue;
 		modAssessmentObject(obj.get(), result);
 		modAssessmentObject(obj.get(), result);
 	}
 	}
 	return result;
 	return result;

+ 5 - 2
mapeditor/mapsettings/translations.cpp

@@ -20,8 +20,11 @@ void Translations::cleanupRemovedItems(CMap & map)
 {
 {
 	std::set<std::string> existingObjects{"map", "header"};
 	std::set<std::string> existingObjects{"map", "header"};
 	for(auto object : map.objects)
 	for(auto object : map.objects)
-		existingObjects.insert(object->instanceName);
-	
+	{
+		if(object)
+			existingObjects.insert(object->instanceName);
+	}
+
 	for(auto & translations : map.translations.Struct())
 	for(auto & translations : map.translations.Struct())
 	{
 	{
 		JsonNode updateTranslations;
 		JsonNode updateTranslations;

+ 2 - 0
mapeditor/validator.cpp

@@ -79,6 +79,8 @@ std::set<Validator::Issue> Validator::validate(const CMap * map)
 		//checking all objects in the map
 		//checking all objects in the map
 		for(auto o : map->objects)
 		for(auto o : map->objects)
 		{
 		{
+			if(!o)
+				continue;
 			//owners for objects
 			//owners for objects
 			if(o->getOwner() == PlayerColor::UNFLAGGABLE)
 			if(o->getOwner() == PlayerColor::UNFLAGGABLE)
 			{
 			{