← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1690519-playercolor into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1690519-playercolor into lp:widelands.

Commit message:
Create playercolor unique_ptr as late as possible.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1690519 in widelands: "Random-seeming crashes in trunk"
  https://bugs.launchpad.net/widelands/+bug/1690519

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1690519-playercolor/+merge/324053

I am assuming that some of the rashes are due to the changes in playercolor caused by this merge:

https://code.launchpad.net/~widelands-dev/widelands/fh1_width_and_mapobject_messages/+merge/318189

So I'm hoping that this change will help.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1690519-playercolor into lp:widelands.
=== modified file 'src/graphic/animation.cc'
--- src/graphic/animation.cc	2017-05-13 13:14:29 +0000
+++ src/graphic/animation.cc	2017-05-15 11:41:00 +0000
@@ -72,7 +72,7 @@
 	                            float scale) const override;
 	uint16_t nr_frames() const override;
 	uint32_t frametime() const override;
-	std::unique_ptr<const Image> representative_image(const RGBColor* clr) const override;
+	const Image* representative_image(const RGBColor* clr) const override;
 	const std::string& representative_image_filename() const override;
 	virtual void blit(uint32_t time,
 	                  const Rectf& source_rect,
@@ -219,7 +219,7 @@
 	return frametime_;
 }
 
-std::unique_ptr<const Image> NonPackedAnimation::representative_image(const RGBColor* clr) const {
+const Image* NonPackedAnimation::representative_image(const RGBColor* clr) const {
 	assert(!image_files_.empty());
 	const Image* image = (hasplrclrs_ && clr) ? playercolor_image(*clr, image_files_[0]) :
 	                                            g_gr->images().get(image_files_[0]);
@@ -228,7 +228,7 @@
 	const int h = image->height();
 	Texture* rv = new Texture(w / scale_, h / scale_);
 	rv->blit(Rectf(0, 0, w / scale_, h / scale_), *image, Rectf(0, 0, w, h), 1., BlendMode::Copy);
-	return std::unique_ptr<const Image>(rv);
+	return rv;
 }
 
 // TODO(GunChleoc): This is only here for the font renderers.
@@ -335,7 +335,7 @@
 	const auto hash = std::make_pair(id, clr);
 	if (representative_images_.count(hash) != 1) {
 		representative_images_.insert(std::make_pair(
-		   hash, std::move(g_gr->animations().get_animation(id).representative_image(clr))));
+		   hash, std::unique_ptr<const Image>(std::move(g_gr->animations().get_animation(id).representative_image(clr)))));
 	}
 	return representative_images_.at(hash).get();
 }

=== modified file 'src/graphic/animation.h'
--- src/graphic/animation.h	2017-05-03 07:24:06 +0000
+++ src/graphic/animation.h	2017-05-15 11:41:00 +0000
@@ -80,7 +80,7 @@
 	/// An image of the first frame, blended with the given player color.
 	/// The 'clr' is the player color used for blending - the parameter can be
 	/// 'nullptr', in which case the neutral image will be returned.
-	virtual std::unique_ptr<const Image> representative_image(const RGBColor* clr) const = 0;
+	virtual const Image* representative_image(const RGBColor* clr) const = 0;
 	/// The filename of the image used for the first frame, without player color.
 	virtual const std::string& representative_image_filename() const = 0;
 

=== modified file 'src/graphic/playercolor.cc'
--- src/graphic/playercolor.cc	2017-04-28 06:47:01 +0000
+++ src/graphic/playercolor.cc	2017-05-15 11:41:00 +0000
@@ -48,10 +48,10 @@
 	const Image* color_mask = g_gr->images().get(color_mask_filename);
 	const int w = image->width();
 	const int h = image->height();
-	auto pc_image = std::unique_ptr<Texture>(new Texture(w, h));
+	Texture* pc_image = new Texture(w, h);
 	pc_image->fill_rect(Rectf(0, 0, w, h), RGBAColor(0, 0, 0, 0));
 	pc_image->blit_blended(Rectf(0, 0, w, h), *image, *color_mask, Rectf(0, 0, w, h), clr);
-	g_gr->images().insert(hash, std::move(pc_image));
+	g_gr->images().insert(hash, std::unique_ptr<const Texture>(std::move(pc_image)));
 	assert(g_gr->images().has(hash));
 	return g_gr->images().get(hash);
 }


Follow ups