Jelajahi Sumber

Fix crash due to missing boat for neutrla heroes

Tomasz Zieliński 2 tahun lalu
induk
melakukan
250b27ba46
2 mengubah file dengan 7 tambahan dan 3 penghapusan
  1. 6 2
      lib/CTownHandler.cpp
  2. 1 1
      lib/CTownHandler.h

+ 6 - 2
lib/CTownHandler.cpp

@@ -110,7 +110,11 @@ void CBuilding::addNewBonus(const std::shared_ptr<Bonus> & b, BonusList & bonusL
 
 CFaction::~CFaction()
 {
-	delete town;
+	if (town)
+	{
+		delete town;
+		town = nullptr;
+	}
 }
 
 int32_t CFaction::getIndex() const
@@ -1029,7 +1033,7 @@ CFaction * CTownHandler::loadFromJson(const std::string & scope, const JsonNode
 	faction->creatureBg120 = source["creatureBackground"]["120px"].String();
 	faction->creatureBg130 = source["creatureBackground"]["130px"].String();
 
-	faction->boatType = EBoatId::NONE;
+	faction->boatType = EBoatId::CASTLE; //Do not crash
 	if (!source["boat"].isNull())
 	{
 		VLC->modh->identifiers.requestIdentifier("core:boat", source["boat"], [=](int32_t boatTypeID)

+ 1 - 1
lib/CTownHandler.h

@@ -207,7 +207,7 @@ public:
 
 	/// Boat that will be used by town shipyard (if any)
 	/// and for placing heroes directly on boat (in map editor, water prisons & taverns)
-	BoatId boatType;
+	BoatId boatType = BoatId(EBoatId::CASTLE);
 
 
 	CTown * town = nullptr; //NOTE: can be null