GunChleoc has proposed merging 
lp:~widelands-dev/widelands/check_representative_image into lp:widelands.

Commit message:
All MapObjectDescr check in the constructor if they have a representative image.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/check_representative_image/+merge/333563

All MapObjectDescr check in the constructor if they have a representative image.

I hope that this will help debug 
https://bugs.launchpad.net/widelands/+bug/1731052
-- 
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/check_representative_image into lp:widelands.
=== modified file 'src/logic/map_objects/map_object.cc'
--- src/logic/map_objects/map_object.cc	2017-09-15 12:33:58 +0000
+++ src/logic/map_objects/map_object.cc	2017-11-10 19:41:13 +0000
@@ -246,6 +246,7 @@
 	if (table.has_key("representative_image")) {
 		representative_image_filename_ = table.get_string("representative_image");
 	}
+	check_representative_image();
 }
 MapObjectDescr::~MapObjectDescr() {
 	anims_.clear();
@@ -301,6 +302,12 @@
 	return representative_image_filename_;
 }
 
+void MapObjectDescr::check_representative_image() {
+	if (representative_image() == nullptr) {
+		throw Widelands::GameDataError("The %s %s has no representative image. Does it have an \"idle\" animation?", to_string(type()).c_str(), name().c_str());
+	}
+}
+
 const Image* MapObjectDescr::icon() const {
 	if (!icon_filename_.empty()) {
 		return g_gr->images().get(icon_filename_);

=== modified file 'src/logic/map_objects/map_object.h'
--- src/logic/map_objects/map_object.h	2017-09-15 12:33:58 +0000
+++ src/logic/map_objects/map_object.h	2017-11-10 19:41:13 +0000
@@ -150,8 +150,7 @@
 	/// nullptr otherwise
 	const Image* representative_image(const RGBColor* player_color = nullptr) const;
 	/// Returns the image fileneme for first frame of the idle animation if the MapObject has
-	/// animations,
-	/// is empty otherwise
+	/// animations, is empty otherwise
 	const std::string& representative_image_filename() const;
 
 	/// Returns the menu image if the MapObject has one, nullptr otherwise
@@ -167,6 +166,9 @@
 	void add_attribute(uint32_t attr);
 
 private:
+	/// Throws an exception if thpe MapObjectDescr has no representative image
+	void check_representative_image();
+
 	using Anims = std::map<std::string, uint32_t>;
 	using AttribMap = std::map<std::string, uint32_t>;
 	using Attributes = std::vector<uint32_t>;

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to